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
- func EncodeInt64(v int64) []byte
- 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 RemoveZTKey(txn *Transaction, metakey []byte) error
- func StartExpire(db *DB) error
- func StartGC(db *DB)
- func StartZT(db *DB, conf *conf.ZT)
- func UUID() []byte
- func UUIDString(id []byte) string
- type DB
- type DBID
- type Hash
- func (hash *Hash) Destory() error
- 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
- func (hash *Hash) HMGet(fields [][]byte) ([][]byte, error)
- func (hash *Hash) HMSet(fields [][]byte, values [][]byte) 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() error
- func (kv *Kv) FlushDB() error
- func (kv *Kv) Keys(start []byte, f func(key []byte) bool) error
- func (kv *Kv) RandomKey() ([]byte, 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 Object
- type ObjectEncoding
- type ObjectType
- type RedisStore
- type Set
- type SetMeta
- type String
- func (s *String) Append(value []byte) (int, error)
- func (s *String) Exist() bool
- func (s *String) Get() ([]byte, 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) 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)
- 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)
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") // 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 )
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 PutZList ¶
func PutZList(txn *Transaction, metakey []byte) error
PutZList should be called after ZList created
func RemoveZTKey ¶
func RemoveZTKey(txn *Transaction, metakey []byte) error
RemoveZTKey remove an metakey from ZT
func UUIDString ¶
UUIDString returns canonical string representation of UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
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 Kv ¶
type Kv struct {
// contains filtered or unexported fields
}
Kv supplies key releated operations
func (*Kv) FlushAll ¶
FlushAll clean up all databases. FIXME one txn is limited for number of entries
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
func NewZList ¶
func NewZList(txn *Transaction, key []byte) List
NewZList create new list object ,the key is not checked for presence
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
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) Incr ¶
Incr increment the integer value by the given amount the old value must be integer
func (*String) Incrf ¶
Incrf increment the float value by the given amount the old value must be float
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 new object thougth key
func (*Transaction) Set ¶
func (txn *Transaction) Set(key []byte) (*Set, error)
Set returns a set object
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
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package zlistproto is a generated protocol buffer package.
|
Package zlistproto is a generated protocol buffer package. |