structure

package
v0.0.0-...-a5c5f28 Latest Latest
Warning

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

Go to latest
Published: May 22, 2019 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SeekThreshold int = 10
)

Variables

View Source
var (
	ErrSetType    = errors.New("invalid set type")
	ErrInvalidTTL = errors.New("invalid ttl value")
	ErrIncrValue  = errors.New("ERR value is not an integer or out of range")
)
View Source
var (
	InvalidFlag = errors.New("invalid flag")
)

Functions

func EncodeDataKey

func EncodeDataKey(dataFlag TypeFlag, prefix []byte, key []byte) kv.Key

func EncodeHashMetaValue

func EncodeHashMetaValue(expireAt int64, count int64) []byte

func EncodeStringMetaValue

func EncodeStringMetaValue(expire int64) []byte

Types

type HashPair

type HashPair struct {
	Field []byte
	Value []byte
}

HashPair is the pair for (field, value) in a hash.

type MetaValue

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

type TxStructure

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

TxStructure supports some simple data structures like string, hash, list, etc... and you can use these in a transaction.

func NewStructure

func NewStructure(reader kv.Retriever, readWriter kv.RetrieverMutator, prefix []byte, ignorettl bool) *TxStructure

NewStructure creates a TxStructure with Retriever, RetrieverMutator and key prefix.

func (*TxStructure) CheckExpireAndDel

func (t *TxStructure) CheckExpireAndDel(keys [][]byte) (bool, error)

func (*TxStructure) Clear

func (t *TxStructure) Clear(key []byte) error

Clear removes the string value of the key.

func (*TxStructure) DEL

func (t *TxStructure) DEL(keys [][]byte) (int, error)

func (*TxStructure) EXPIRE

func (t *TxStructure) EXPIRE(key []byte, ttl []byte) (int, error)

func (*TxStructure) EncodeMetaKey

func (t *TxStructure) EncodeMetaKey(key []byte) kv.Key

func (*TxStructure) ExpireAt

func (t *TxStructure) ExpireAt(key []byte, ttl []byte) (int, error)

func (*TxStructure) Get

func (t *TxStructure) Get(key []byte) ([]byte, error)

Get gets the string value of a key.

func (*TxStructure) GetInt64

func (t *TxStructure) GetInt64(key []byte) (int64, error)

GetInt64 gets the int64 value of a key.

func (*TxStructure) HClear

func (t *TxStructure) HClear(key []byte) error

HClear removes the hash value of the key.

func (*TxStructure) HDel

func (t *TxStructure) HDel(key []byte, fields [][]byte) (int, error)

HDel deletes one or more hash fields.

func (*TxStructure) HGet

func (t *TxStructure) HGet(key []byte, field []byte) ([]byte, error)

HGet gets the value of a hash field.

func (*TxStructure) HGetAll

func (t *TxStructure) HGetAll(key []byte) ([][]byte, error)

HGetAll gets all the fields and values in a hash.

func (*TxStructure) HGetInt64

func (t *TxStructure) HGetInt64(key []byte, field []byte) (int64, error)

HGetInt64 gets int64 value of a hash field.

func (*TxStructure) HInc

func (t *TxStructure) HInc(key []byte, field []byte, step int64) (int64, error)

HInc increments the integer value of a hash field, by step, returns the value after the increment.

func (*TxStructure) HKeys

func (t *TxStructure) HKeys(key []byte) ([][]byte, error)

HKeys gets all the fields in a hash.

func (*TxStructure) HLen

func (t *TxStructure) HLen(key []byte) (int, error)

HLen gets the number of fields in a hash.

func (*TxStructure) HMSet

func (t *TxStructure) HMSet(key []byte, elements []*HashPair) ([]byte, error)

func (*TxStructure) HSet

func (t *TxStructure) HSet(key []byte, field []byte, value []byte) (int, error)

HSet sets the string value of a hash field.

func (*TxStructure) IncInt64

func (t *TxStructure) IncInt64(key []byte, step int64) (int64, error)

func (*TxStructure) LClear

func (t *TxStructure) LClear(key []byte) error

LClear removes the list of the key.

func (*TxStructure) LIndex

func (t *TxStructure) LIndex(key []byte, index int64) ([]byte, error)

LIndex gets an element from a list by its index.

func (*TxStructure) LLen

func (t *TxStructure) LLen(key []byte) (int64, error)

LLen gets the length of a list.

func (*TxStructure) LPop

func (t *TxStructure) LPop(key []byte) ([]byte, error)

LPop removes and gets the first element in a list.

func (*TxStructure) LPush

func (t *TxStructure) LPush(key []byte, values ...[]byte) error

LPush prepends one or multiple values to a list.

func (*TxStructure) LSet

func (t *TxStructure) LSet(key []byte, index int64, value []byte) error

LSet updates an element in the list by its index.

func (*TxStructure) MergedHClear

func (t *TxStructure) MergedHClear(key []byte) error

func (*TxStructure) MergedHDel

func (t *TxStructure) MergedHDel(key []byte, fields [][]byte) (int, error)

HDel deletes one or more hash fields.

func (*TxStructure) MergedHGet

func (t *TxStructure) MergedHGet(key []byte, field []byte) ([]byte, error)

func (*TxStructure) MergedHGetAll

func (t *TxStructure) MergedHGetAll(key []byte) ([][]byte, error)

func (*TxStructure) MergedHGetInt64

func (t *TxStructure) MergedHGetInt64(key []byte, field []byte) (int64, error)

func (*TxStructure) MergedHIncInt64

func (t *TxStructure) MergedHIncInt64(key []byte, field []byte, step int64) (int64, error)

func (*TxStructure) MergedHKeys

func (t *TxStructure) MergedHKeys(key []byte) ([][]byte, error)

func (*TxStructure) MergedHMGet

func (t *TxStructure) MergedHMGet(key []byte, fields [][]byte) ([][]byte, error)

func (*TxStructure) MergedHMSet

func (t *TxStructure) MergedHMSet(key []byte, elements []*HashPair) ([]byte, error)

func (*TxStructure) MergedHSet

func (t *TxStructure) MergedHSet(key []byte, field []byte, value []byte) (int, error)

HSet sets the string value of a hash field.

func (*TxStructure) RPop

func (t *TxStructure) RPop(key []byte) ([]byte, error)

RPop removes and gets the last element in a list.

func (*TxStructure) RPush

func (t *TxStructure) RPush(key []byte, values ...[]byte) error

RPush appends one or multiple values to a list.

func (*TxStructure) Set

func (t *TxStructure) Set(key []byte, value []byte) ([]byte, error)

Set sets the string value of the key.

func (*TxStructure) SetWithTTL

func (t *TxStructure) SetWithTTL(key []byte, value []byte, ttl int64) ([]byte, error)

func (*TxStructure) TTL

func (t *TxStructure) TTL(key []byte) (int, error)

type TypeFlag

type TypeFlag byte

TypeFlag is for data structure meta/data flag.

const (
	MetaCode TypeFlag = '#'
	DataCode TypeFlag = '&'

	// StringMeta is the flag for string meta.
	//StringMeta TypeFlag = 'S'
	// StringData is the flag for string data.
	StringData TypeFlag = 's'
	// HashMeta is the flag for hash meta.
	//HashMeta TypeFlag = 'H'
	// HashData is the flag for hash data.
	HashData TypeFlag = 'h'
	// ListMeta is the flag for list meta.
	ListMeta TypeFlag = 'L'
	// ListData is the flag for list data.
	ListData TypeFlag = 'l'
	ERRCode  TypeFlag = 'E'
)

func DecodeMetaKey

func DecodeMetaKey(prefix []byte, ek kv.Key) (TypeFlag, []byte, error)

func DecodeMetaValue

func DecodeMetaValue(value []byte) (TypeFlag, int64, int64)

Jump to

Keyboard shortcuts

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