list

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2022 License: MIT Imports: 2 Imported by: 0

README

list

List is an in-memory Redis like list datastructure in Go

Getting Started

Installing

To start using hash, install Go and run go get:

$ go get -u github.com/arriqaaq/list

This will retrieve the library.

Usage

package main

import "github.com/arriqaaq/list"

type kv struct{k,v string}

func main() {
    key:="set1"

    list := list.New()
	list.LPush(key, []byte("a"), []byte("b"), []byte("c"))
	list.LPush(key, []byte("d"), []byte("e"), []byte("f"))

    list2 := list.New()
	list2.LPush(key, &kv{"a","b"}, &kv{"c","d"})

    list3 := list.New()
	list2.LPush(key, 1, 2, 3)

}
Supported commands

LINDEX
LINSERT
LLEN
LMOVE
LPOP
LPOS
LPUSH
LRANGE
LREM
LSET
LTRIM
RPOP
RPUSH

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InsertType

type InsertType string
const (
	Before InsertType = "BEFORE"
	After  InsertType = "AFTER"
)

type List

type List struct {
	// contains filtered or unexported fields
}

func New

func New() *List

func (*List) Keys

func (l *List) Keys() []string

func (*List) LClear

func (l *List) LClear(key string)

LClear clear a specified key for List.

func (*List) LIndex

func (l *List) LIndex(key string, index int) (val interface{})

LIndex returns the element at index index in the list stored at key. The index is zero-based, so 0 means the first element, 1 the second element and so on. Negative indices can be used to designate elements starting at the tail of the list. Here, -1 means the last element, -2 means the penultimate and so forth.

func (*List) LInsert

func (l *List) LInsert(key string, option InsertType, pivot, val interface{}) int

LInsert inserts element in the list stored at key either before or after the reference value pivot.

func (*List) LKeyExists

func (l *List) LKeyExists(key string) (ok bool)

LKeyExists check if the key of a List exists.

func (*List) LLen

func (l *List) LLen(key string) (length int)

LLen returns the length of the list stored at key. If key does not exist, it is interpreted as an empty list and 0 is returned.

func (*List) LPop

func (l *List) LPop(key string) interface{}

LPop removes and returns the first elements of the list stored at key.

func (*List) LPush

func (l *List) LPush(key string, val ...interface{}) int

LPush insert all the specified values at the head of the list stored at key. If key does not exist, it is created as empty list before performing the push operations.

func (*List) LRange

func (l *List) LRange(key string, start, end int) []interface{}

LRange returns the specified elements of the list stored at key. The offsets start and stop are zero-based indexes, with 0 being the first element of the list (the head of the list), 1 being the next element and so on. These offsets can also be negative numbers indicating offsets starting at the end of the list. For example, -1 is the last element of the list, -2 the penultimate, and so on.

func (*List) LRem

func (l *List) LRem(key string, val interface{}, count int) int

LRem removes the first count occurrences of elements equal to element from the list stored at key. The count argument influences the operation in the following ways: count > 0: Remove elements equal to element moving from head to tail. count < 0: Remove elements equal to element moving from tail to head. count = 0: Remove all elements equal to element.

func (*List) LSet

func (l *List) LSet(key string, index int, val interface{}) bool

LSet sets the list element at index to element.

func (*List) LTrim

func (l *List) LTrim(key string, start, end int) bool

LTrim trim an existing list so that it will contain only the specified range of elements specified. Both start and stop are zero-based indexes, where 0 is the first element of the list (the head), 1 the next element and so on.

func (*List) RPop

func (l *List) RPop(key string) interface{}

RPop removes and returns the last elements of the list stored at key.

func (*List) RPush

func (l *List) RPush(key string, val ...interface{}) int

RPush insert all the specified values at the tail of the list stored at key. If key does not exist, it is created as empty list before performing the push operation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL