Documentation ¶
Index ¶
- Constants
- Variables
- func BatchGetValues(txn *Transaction, keys [][]byte) ([][]byte, error)
- func DataKey(db *DB, key []byte) []byte
- func DecodeFloat64(d []byte) float64
- func DecodeInt64(b []byte) int64
- func EncodeFloat64(v float64) ([]byte, error)
- func EncodeHashMeta(meta *HashMeta) []byte
- func EncodeInt64(v int64) ([]byte, error)
- func EncodeObject(obj *Object) []byte
- func IsExpired(obj *Object, now int64) bool
- func MetaKey(db *DB, key []byte) []byte
- func Now() int64
- func PutZList(txn *Transaction, metakey []byte) error
- func RemoveRepByMap(members [][]byte) [][]byte
- func RemoveZTKey(txn *Transaction, metakey []byte) error
- func StartExpire(db *DB, conf *conf.Expire)
- func StartGC(db *DB, conf *conf.GC)
- func StartTiKVGC(db *DB, tikvCfg *conf.TiKVGC)
- func StartZT(db *DB, conf *conf.ZT)
- func UUID() []byte
- func UUIDString(id []byte) string
- func ZSetScorePrefix(dkey []byte) []byte
- type DB
- type DBID
- type Hash
- func (hash *Hash) Exists() bool
- func (hash *Hash) HDel(fields [][]byte) (int64, error)
- func (hash *Hash) HExists(field []byte) (bool, error)
- func (hash *Hash) HGet(field []byte) ([]byte, error)
- func (hash *Hash) HGetAll() ([][]byte, [][]byte, error)
- func (hash *Hash) HIncrBy(field []byte, v int64) (int64, error)
- func (hash *Hash) HIncrByFloat(field []byte, v float64) (float64, error)
- func (hash *Hash) HLen() (int64, error)
- func (hash *Hash) HMGet(fields [][]byte) ([][]byte, error)
- func (hash *Hash) HMSet(fields, values [][]byte) error
- func (hash *Hash) HScan(cursor []byte, f func(key, val []byte) bool) error
- func (hash *Hash) HSet(field []byte, value []byte) (int, error)
- func (hash *Hash) HSetNX(field []byte, value []byte) (int, error)
- type HashMeta
- type Iterator
- type Kv
- func (kv *Kv) Delete(keys [][]byte) (int64, error)
- func (kv *Kv) Exists(keys [][]byte) (int64, error)
- func (kv *Kv) ExpireAt(key []byte, at int64) error
- func (kv *Kv) FlushAll(ctx context.Context) error
- func (kv *Kv) FlushDB(ctx context.Context) error
- func (kv *Kv) Keys(start []byte, f func(key []byte) bool) error
- func (kv *Kv) RandomKey() ([]byte, error)
- func (kv *Kv) Touch(keys [][]byte) (int64, error)
- type LList
- func (l *LList) Destory() error
- func (l *LList) Exist() bool
- func (l *LList) Index(n int64) (data []byte, err error)
- func (l *LList) Insert(pivot, v []byte, before bool) error
- func (l *LList) LPop() (data []byte, err error)
- func (l *LList) LPush(data ...[]byte) (err error)
- func (l *LList) LRem(v []byte, n int64) (int, error)
- func (l *LList) LTrim(start int64, stop int64) error
- func (l *LList) Length() int64
- func (l *LList) RPop() ([]byte, error)
- func (l *LList) RPush(data ...[]byte) (err error)
- func (l *LList) Range(left, right int64) (value [][]byte, err error)
- func (l *LList) Set(n int64, data []byte) error
- type LListMeta
- type Lease
- type List
- type ListOption
- type MemberScore
- type Object
- type ObjectEncoding
- type ObjectType
- type RedisStore
- type Set
- func (set *Set) Exists() bool
- func (set *Set) Iter() (*SetIter, error)
- func (set *Set) SAdd(members ...[]byte) (int64, error)
- func (set *Set) SCard() (int64, error)
- func (set *Set) SIsmember(member []byte) (int64, error)
- func (set *Set) SMembers() ([][]byte, error)
- func (set *Set) SMove(destination []byte, member []byte) (int64, error)
- func (set *Set) SPop(count int64) ([][]byte, error)
- func (set *Set) SRem(members [][]byte) (int64, error)
- type SetIter
- type SetMeta
- type String
- func (s *String) Append(value []byte) (int, error)
- func (s *String) BitCount(begin, end int) (int, error)
- func (s *String) BitOpAnd()
- func (s *String) BitOpNot()
- func (s *String) BitOpOr()
- func (s *String) BitOpXor()
- func (s *String) BitPos(bit, begin, end int) (int, error)
- func (s *String) Exist() bool
- func (s *String) Get() ([]byte, error)
- func (s *String) GetBit(offset int) (int, error)
- func (s *String) GetRange(start, end int) []byte
- func (s *String) GetSet(value []byte) ([]byte, error)
- func (s *String) Incr(delta int64) (int64, error)
- func (s *String) Incrf(delta float64) (float64, error)
- func (s *String) Len() (int, error)
- func (s *String) Set(val []byte, expire ...int64) error
- func (s *String) SetBit(offset, on int) (int, error)
- func (s *String) SetRange(offset int64, value []byte) ([]byte, error)
- type StringMeta
- type Transaction
- func (txn *Transaction) Commit(ctx context.Context) error
- func (txn *Transaction) Destory(obj *Object, key []byte) error
- func (txn *Transaction) Hash(key []byte) (*Hash, error)
- func (txn *Transaction) Kv() *Kv
- func (txn *Transaction) List(key []byte, opts ...ListOption) (List, error)
- func (txn *Transaction) LockKeys(keys ...[]byte) error
- func (txn *Transaction) Object(key []byte) (*Object, error)
- func (txn *Transaction) Rollback() error
- func (txn *Transaction) Set(key []byte) (*Set, error)
- func (txn *Transaction) String(key []byte) (*String, error)
- func (txn *Transaction) Strings(keys [][]byte) ([]*String, error)
- func (txn *Transaction) ZSet(key []byte) (*ZSet, error)
- type ZList
- func (l *ZList) Destory() error
- func (l *ZList) Exist() bool
- func (l *ZList) Index(n int64) (data []byte, err error)
- func (l *ZList) Insert(pivot, v []byte, before bool) error
- func (l *ZList) LPop() (data []byte, err error)
- func (l *ZList) LPush(data ...[]byte) (err error)
- func (l *ZList) LRem(v []byte, n int64) (int, error)
- func (l *ZList) LTrim(start int64, stop int64) error
- func (l *ZList) Length() int64
- func (l *ZList) Marshal() ([]byte, error)
- func (l *ZList) RPop() ([]byte, error)
- func (l *ZList) RPush(data ...[]byte) (err error)
- func (l *ZList) Range(left, right int64) (value [][]byte, err error)
- func (l *ZList) Set(n int64, data []byte) error
- func (l *ZList) TransferToLList(dbns []byte, dbid DBID, key []byte) (*LList, error)
- func (l *ZList) Unmarshal(obj *Object, b []byte) (err error)
- type ZSet
- func (zset *ZSet) Exist() bool
- func (zset *ZSet) MGet(members [][]byte) ([][]byte, error)
- func (zset *ZSet) ZAdd(members [][]byte, scores []float64) (int64, error)
- func (zset *ZSet) ZAnyOrderRange(start int64, stop int64, withScore bool, positiveOrder bool) ([][]byte, error)
- func (zset *ZSet) ZAnyOrderRangeByScore(startScore float64, startInclude bool, stopScore float64, stopInclude bool, ...) ([][]byte, error)
- func (zset *ZSet) ZCard() int64
- func (zset *ZSet) ZRem(members [][]byte) (int64, error)
- func (zset *ZSet) ZScore(member []byte) ([]byte, error)
- type ZSetMeta
Constants ¶
const ( // Separator of the key segment Separator = ":" // ObjectEncodingLength indecate current object marshaled length ObjectEncodingLength = 42 )
const ( ObjectEncodingRaw = ObjectEncoding(iota) ObjectEncodingInt ObjectEncodingHT ObjectEncodingZipmap ObjectEncodingLinkedlist ObjectEncodingZiplist ObjectEncodingIntset ObjectEncodingSkiplist ObjectEncodingEmbstr ObjectEncodingQuicklist )
Encoding values, see https://github.com/antirez/redis/blob/unstable/src/server.h#L581
const ( ObjectString = ObjectType(iota) ObjectList ObjectSet ObjectZSet ObjectHash )
Object types, see https://github.com/antirez/redis/blob/unstable/src/server.h#L461
Variables ¶
var ( // ErrTypeMismatch indicates object type of key is not as expect ErrTypeMismatch = errors.New("type mismatch") // ErrKeyNotFound key not exist ErrKeyNotFound = errors.New("key not found") // ErrInteger valeu is not interge ErrInteger = errors.New("value is not an integer or out of range") // ErrPrecision list index reach precision limitatin ErrPrecision = errors.New("list reaches precision limitation, rebalance now") // ErrOutOfRange index/offset out of range ErrOutOfRange = errors.New("error index/offset out of range") // ErrInvalidLength data length is invalid for unmarshaler" ErrInvalidLength = errors.New("error data length is invalid for unmarshaler") // ErrEncodingMismatch object encoding type ErrEncodingMismatch = errors.New("error object encoding type") // ErrStorageRetry storage err and try again later ErrStorageRetry = errors.New("Storage err and try again later") //ErrSetNilValue means the value corresponding to key is a non-zero value ErrSetNilValue = errors.New("The value corresponding to key is a non-zero value") // IsErrNotFound returns true if the key is not found, otherwise return false IsErrNotFound = store.IsErrNotFound // IsRetryableError returns true if the error is temporary and can be retried IsRetryableError = store.IsRetryableError // IsConflictError return true if the error is conflict IsConflictError = store.IsConflictError NilValue = []byte{0} )
var SetNilValue = []byte{0}
SetNilValue is the value set to a tikv key for tikv do not support a real empty value
Functions ¶
func BatchGetValues ¶
func BatchGetValues(txn *Transaction, keys [][]byte) ([][]byte, error)
BatchGetValues issues batch requests to get values
func DecodeFloat64 ¶
DecodeFloat64 decode the float64 object from binary
func EncodeFloat64 ¶
EncodeFloat64 encode the float64 object to binary
func EncodeHashMeta ¶ added in v0.6.0
EncodeHashMeta encodes meta data into byte slice
func EncodeInt64 ¶
EncodeInt64 encode the int64 object to binary
func PutZList ¶
func PutZList(txn *Transaction, metakey []byte) error
PutZList should be called after ZList created
func RemoveRepByMap ¶ added in v0.6.0
RemoveRepByMap filters duplicate elements through the map's unique primary key feature
func RemoveZTKey ¶
func RemoveZTKey(txn *Transaction, metakey []byte) error
RemoveZTKey remove an metakey from ZT
func StartTiKVGC ¶ added in v0.6.0
StartTiKVGC start tikv gcwork
func UUIDString ¶
UUIDString returns canonical string representation of UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
func ZSetScorePrefix ¶ added in v0.6.0
ZSetScorePrefix builds a score key prefix from a redis key
Types ¶
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
Hash implements the hashtable
func GetHash ¶
func GetHash(txn *Transaction, key []byte) (*Hash, error)
GetHash returns a hash object, create new one if nonexists
func (*Hash) HIncrBy ¶
HIncrBy increments the number stored at field in the hash stored at key by increment
func (*Hash) HIncrByFloat ¶
HIncrByFloat increment the specified field of a hash stored at key, and representing a floating point number, by the specified increment
func (*Hash) HMGet ¶
HMGet returns the values associated with the specified fields in the hash stored at key
func (*Hash) HMSet ¶
HMSet sets the specified fields to their respective values in the hash stored at key
type HashMeta ¶
type HashMeta struct {
Object
}
HashMeta is the meta data of the hashtable
func DecodeHashMeta ¶ added in v0.6.0
DecodeHashMeta decode meta data into meta field
type Kv ¶
type Kv struct {
// contains filtered or unexported fields
}
Kv supplies key releated operations
type LList ¶
type LList struct { LListMeta // contains filtered or unexported fields }
LList is a distributed object that works like a double link list {Object schema}:{index} -> value
func (*LList) Insert ¶
Insert value in the list stored at key either before or after the reference value pivot 1. pivot berfore/ pivot/ next --> real indexs
func (*LList) LPop ¶
LPop returns and deletes the left most element 0. calculate data key 1. iterate to last value 2. get the key and call kv delete 3. modify the new index in meta
func (*LList) LPush ¶
LPush adds new elements to the left 1. calculate index 2. encode object and call kv 3. modify the new index in meta
func (*LList) LRem ¶
LRem removes the first count occurrences of elements equal to value from the list stored at key
func (*LList) LTrim ¶
LTrim an existing list so that it will contain only the specified range of elements specified
type LListMeta ¶
LListMeta keeps all meta info of a list object after marshaled, listmeta raw data should organized like below |----object 34----| |------len 8------| |----linedx 8-----| |----rindex 8-----|
type Lease ¶
Lease is an object that can be associated with other objects those can share the same ttl of the lease
type List ¶
type List interface { Index(n int64) (data []byte, err error) Insert(pivot, v []byte, before bool) error LPop() (data []byte, err error) LPush(data ...[]byte) (err error) RPop() (data []byte, err error) RPush(data ...[]byte) (err error) Range(left, right int64) (value [][]byte, err error) LRem(v []byte, n int64) (int, error) Set(n int64, data []byte) error LTrim(start int64, stop int64) error Length() int64 Exist() bool Destory() error }
List defines the list interface
func GetList ¶
func GetList(txn *Transaction, key []byte, opts ...ListOption) (List, error)
GetList returns a List object, it creates a new one if the key does not exist, when UseZip() is set, it will create a ziplist instead of a linklist
type MemberScore ¶ added in v0.6.0
type Object ¶
type Object struct { ID []byte Type ObjectType //refer to redis Encoding ObjectEncoding //refer to redis CreatedAt int64 UpdatedAt int64 ExpireAt int64 }
Object meta schema
Layout {DB}:{TAG}:{Key} DB [0-255] Key Usersapce key TAG M(Meta), D(Data)
Object data schema
Layout: {DB}:{TAG}:{ID}:{Others} ID Object ID, ID is not used for meta
String schema (associated value with meta)
Layout: {DB}:M:{key}
func DecodeObject ¶
DecodeObject decode the object from binary
type ObjectEncoding ¶
type ObjectEncoding byte
ObjectEncoding is the encoding type of an object
func (ObjectEncoding) String ¶
func (enc ObjectEncoding) String() string
String representation of ObjectEncoding
type RedisStore ¶
RedisStore wraps store.Storage
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set implements the set data structure
func GetSet ¶
func GetSet(txn *Transaction, key []byte) (*Set, error)
GetSet returns a set object, create new one if nonexists
func (*Set) SCard ¶ added in v0.6.0
SCard returns the set cardinality (number of elements) of the set stored at key
func (*Set) SIsmember ¶ added in v0.6.0
SIsmember returns if member is a member of the set stored at key
func (*Set) SMove ¶ added in v0.6.0
SMove movies member from the set at source to the set at destination
type SetIter ¶ added in v0.6.0
SetIter is the struct of Iterator and prefix
type String ¶
type String struct { Meta StringMeta // contains filtered or unexported fields }
String object operate tikv
func GetString ¶
func GetString(txn *Transaction, key []byte) (*String, error)
GetString return string object , if key is exist , object load meta otherwise object is null if key is not exist and err is not found otherwise return err
func NewString ¶
func NewString(txn *Transaction, key []byte) *String
NewString create new string object
func (*String) BitCount ¶ added in v0.6.0
BitCount counts the number of set bits (population counting) in a string.
func (*String) GetBit ¶ added in v0.6.0
GetBit key offset bitvalye offset / 8 > the index of value offset mod 8 +1
func (*String) Incr ¶
Incr increments the integer value by the given amount the old value must be integer
func (*String) Incrf ¶
Incrf increments the float value by the given amount the old value must be float
func (*String) Set ¶
Set set the string value of a key the num of expire slice is not zero and expire[0] is not zero ,the key add exprie queue otherwise the delete expire queue
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction supplies transaction for data structures
func (*Transaction) Commit ¶
func (txn *Transaction) Commit(ctx context.Context) error
Commit a transaction
func (*Transaction) Destory ¶
func (txn *Transaction) Destory(obj *Object, key []byte) error
Destory the object
func (*Transaction) Hash ¶
func (txn *Transaction) Hash(key []byte) (*Hash, error)
Hash returns a hash object
func (*Transaction) List ¶
func (txn *Transaction) List(key []byte, opts ...ListOption) (List, error)
List return a lists object, a new list is created if the key dose not exist.
func (*Transaction) LockKeys ¶
func (txn *Transaction) LockKeys(keys ...[]byte) error
LockKeys tries to lock the entries with the keys in KV store.
func (*Transaction) Object ¶
func (txn *Transaction) Object(key []byte) (*Object, error)
Object returns the object associated with the key
func (*Transaction) Set ¶
func (txn *Transaction) Set(key []byte) (*Set, error)
Set returns a set object
func (*Transaction) String ¶
func (txn *Transaction) String(key []byte) (*String, error)
String returns a string object, but the object is unsafe, maybe the object is expire,or not exist
type ZList ¶
type ZList struct { Object // contains filtered or unexported fields }
ZList ZListMeta defined zip list, with only objectMeta info.
func GetZList ¶
GetZList generate List objectm with auto reation, if zip is true, zipped list will be choose
func (*ZList) TransferToLList ¶
TransferToLList create an llist and put values into llist from zlist, LList will inheritance information from ZList
type ZSet ¶ added in v0.6.0
type ZSet struct {
// contains filtered or unexported fields
}
ZSet implements the the sorted set
func GetZSet ¶ added in v0.6.0
func GetZSet(txn *Transaction, key []byte) (*ZSet, error)
GetZSet returns a sorted set, create new one if don't exists
func (*ZSet) ZAnyOrderRange ¶ added in v0.6.0
func (*ZSet) ZAnyOrderRangeByScore ¶ added in v0.6.0
func (zset *ZSet) ZAnyOrderRangeByScore(startScore float64, startInclude bool, stopScore float64, stopInclude bool, withScore bool, offset int64, count int64, positiveOrder bool) ([][]byte, error)
ZAnyOrderRangeByScore returns the items of a zset in specific order
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package zlistproto is a generated protocol buffer package.
|
Package zlistproto is a generated protocol buffer package. |