list

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2021 License: MIT Imports: 2 Imported by: 2

Documentation

Overview

Example
package main

import "fmt"

var listKey = "my_list"

func main() {
	list := New()
	list.LPush(listKey, [][]byte{[]byte("a"), []byte("b"), []byte("c")}...)
	list.RPush(listKey, [][]byte{[]byte("a"), []byte("b"), []byte("c")}...)

	list.LPop(listKey)
	list.RPop(listKey)

	length := list.LLen(listKey)
	fmt.Println(length)

	list.LSet(listKey, 10, []byte("d"))
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InsertOption

type InsertOption uint8

InsertOption insert option for LInsert.

const (
	// Before insert before pivot.
	Before InsertOption = iota
	// After insert after pivot.
	After
)

type List

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

List list idx.

func New

func New() *List

New create a new list idx.

func (*List) LClear added in v1.2.8

func (lis *List) LClear(key string)

LClear clear a specified key for List.

func (*List) LIndex

func (lis *List) LIndex(key string, index int) []byte

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 (lis *List) LInsert(key string, option InsertOption, pivot, val []byte) int

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

func (*List) LKeyExists added in v1.2.8

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

LKeyExists check if the key of a List exists.

func (*List) LLen

func (lis *List) LLen(key string) 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 (lis *List) LPop(key string) []byte

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

func (*List) LPush

func (lis *List) LPush(key string, val ...[]byte) 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 (lis *List) LRange(key string, start, end int) [][]byte

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 (lis *List) LRem(key string, val []byte, 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 (lis *List) LSet(key string, index int, val []byte) bool

LSet sets the list element at index to element.

func (*List) LTrim

func (lis *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) LValExists added in v1.2.8

func (lis *List) LValExists(key string, val []byte) (ok bool)

LValExists check if the val exists in a specified List stored at key.

func (*List) RPop

func (lis *List) RPop(key string) []byte

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

func (*List) RPush

func (lis *List) RPush(key string, val ...[]byte) 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.

type Record

type Record map[string]*list.List

Record list record to save.

Jump to

Keyboard shortcuts

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