Documentation ¶
Index ¶
- Constants
- type GetRangeOptions
- type Item
- type List
- func (list *List) ForEachF(f func(a string))
- func (l *List) LIndex(index int) (string, bool)
- func (l *List) LInsert(isBefore bool, pivot, value string) int
- func (l *List) LPop() (string, bool)
- func (l *List) LPush(values ...string) int
- func (l *List) LRange(start int, end int) []string
- func (l *List) LRem(count int, value string) int
- func (l *List) LSet(index int, value string) error
- func (l *List) LTrim(start int, end int) bool
- func (l *List) Len() int
- func (s *List) Marshal() ([]byte, error)
- func (l *List) RPop() (string, bool)
- func (l *List) RPush(values ...string) int
- func (l List) Type() uint64
- func (l List) TypeFancy() string
- func (l *List) Value() interface{}
- type Score
- type SerdeZSet
- type Set
- func (s *Set) AddMember(keys ...string)
- func (s *Set) Diff(o *Set) *Set
- func (s *Set) Exists(key string) bool
- func (s *Set) ForEachF(f func(a string) bool)
- func (s *Set) GetMembers() []string
- func (s *Set) GetRandomMember() *string
- func (s *Set) Intersect(o *Set) *Set
- func (s *Set) Len() int
- func (s *Set) Marshal() ([]byte, error)
- func (s *Set) Pop() *string
- func (s *Set) RemoveMember(key string) bool
- func (s *Set) ToZSet() *ZSet
- func (l *Set) Type() uint64
- func (l *Set) TypeFancy() string
- func (s *Set) Union(o *Set) *Set
- func (s *Set) Value() interface{}
- type SortedSet
- func (ss *SortedSet) AddOrUpdate(key string, score float64) bool
- func (ss *SortedSet) FindNodeByLex(key string) (*SortedSetNode, int)
- func (ss *SortedSet) FindRankOfKey(key string) int
- func (ss *SortedSet) GetByIndex(rank int, remove bool) *SortedSetNode
- func (ss *SortedSet) GetByKey(key string) *SortedSetNode
- func (ss *SortedSet) GetRangeByIndex(start int, end int, options GetRangeOptions) []*SortedSetNode
- func (ss *SortedSet) GetRangeByLex(start string, end string, options GetRangeOptions) []*SortedSetNode
- func (ss *SortedSet) GetRangeByRank(start int, end int, options GetRangeOptions) []*SortedSetNode
- func (ss *SortedSet) GetRangeByScore(start float64, end float64, options GetRangeOptions) []*SortedSetNode
- func (ss *SortedSet) Len() int
- func (ss *SortedSet) PeekMax() *SortedSetNode
- func (ss *SortedSet) PeekMin() *SortedSetNode
- func (ss *SortedSet) PopMax() *SortedSetNode
- func (ss *SortedSet) PopMin() *SortedSetNode
- func (ss *SortedSet) Remove(key string) *SortedSetNode
- func (ss *SortedSet) RemoveByRank(rank int) *SortedSetNode
- func (ss *SortedSet) SanitizeIndex(start int, end int, reverse bool) (int, int)
- type SortedSetLevel
- type SortedSetNode
- type String
- func (s *String) AsBytes() []byte
- func (s *String) AsString() string
- func (s *String) Get(idx int) byte
- func (s *String) Len() int
- func (s *String) Marshal() ([]byte, error)
- func (s *String) SubString(start, end int) string
- func (l *String) Type() uint64
- func (l *String) TypeFancy() string
- func (s *String) Value() interface{}
- type ZSet
- func (ss *ZSet) AddOrUpdate(key string, score float64) bool
- func (s *ZSet) Diff(o *ZSet) *ZSet
- func (ss *ZSet) FindNodeByLex(key string) (*SortedSetNode, int)
- func (ss *ZSet) GetByKey(key string) *SortedSetNode
- func (ss *ZSet) GetRangeByRank(start int, end int, options GetRangeOptions) []*SortedSetNode
- func (s *ZSet) Intersect(o *ZSet, mode int, weight float64) *ZSet
- func (s ZSet) Len() int
- func (s *ZSet) Marshal() ([]byte, error)
- func (ss *ZSet) Remove(key string) *SortedSetNode
- func (s *ZSet) ToSet() *Set
- func (l ZSet) Type() uint64
- func (l ZSet) TypeFancy() string
- func (s *ZSet) Union(o *ZSet, mode int, weight float64) *ZSet
- func (s *ZSet) Value() interface{}
Constants ¶
const ( ValueTypeList = iota ValueTypeString ValueTypeSet ValueTypeZSet )
const ( ValueTypeFancyList = "list" ValueTypeFancyString = "string" ValueTypeFancySet = "set" ValueTypeFancyZSet = "zset" )
const SKIPLIST_MAXLEVEL = 32 /* Should be enough for 2^64 elements */
const SKIPLIST_P = 0.25 /* Skiplist P = 1/4 */
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GetRangeOptions ¶
type GetRangeOptions struct { Reverse bool // Start iterating from the back Offset int // How many nodes to skip Limit int // limit the max nodes to return StartExclusive bool // exclude start value, so it search in interval (start, end] or (start, end) StopExclusive bool // exclude end value, so it search in interval [start, end) or (start, end) }
TODO: Add reverse, offset
func DefaultRangeOptions ¶
func DefaultRangeOptions() GetRangeOptions
type Item ¶
type Item interface { // The pointer to the value. Value() interface{} // The id of the type of the Item. // This need to be constant for the type because it is // used when de-/serializing item from/to disk. Type() uint64 TypeFancy() string }
The item interface. An item is the value of a key.
type List ¶
type List struct {
// contains filtered or unexported fields
}
func ListUnmarshal ¶
func NewListFromArr ¶
func (*List) LPop ¶
RPop pops the front of the list and returns the value. Returns true if its valid, false otherwise.
func (*List) LTrim ¶
LTrim see redis docs - returns true if list is now emptied so the key can be deleted.
func (*List) RPop ¶
RPop pops the back of the list and returns the value. Returns true if its valid, false otherwise.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
func NewSetEmpty ¶
func NewSetEmpty() *Set
func NewSetFromMap ¶
func SetUnmarshal ¶
func (*Set) ForEachF ¶
ForEachF loops over the set calling f on each elements until it returns false.
func (*Set) GetMembers ¶
func (*Set) GetRandomMember ¶
GetRandomMeber returns a random member from the set.
func (*Set) Intersect ¶
Intersect returns a new Set that is an intersection of both sets. TODO: Better intersection algorithm?
func (*Set) RemoveMember ¶
RemoveMember removes the given member from the set. Returns true if the key exists. False otherwise.
type SortedSet ¶
type SortedSet struct { Dict map[string]*SortedSetNode // contains filtered or unexported fields }
func (*SortedSet) AddOrUpdate ¶
Add an element into the sorted set with specific key / value / score. If the element is added, this method returns true; otherwise false means updated.
Time complexity: O(log(N)) with high probability
func (*SortedSet) FindNodeByLex ¶
func (ss *SortedSet) FindNodeByLex(key string) (*SortedSetNode, int)
FindNodeByLex returns the node with the requested key
Time complexity: O(log(N)) with high probability
func (*SortedSet) FindRankOfKey ¶
Find the rank of the node specified by key Note that the rank is 1-based integer. Rank 1 means the first node
If the node is not found, 0 is returned. Otherwise rank(>0) is returned
Time complexity: O(log(N)) with high probability
func (*SortedSet) GetByIndex ¶
func (ss *SortedSet) GetByIndex(rank int, remove bool) *SortedSetNode
Get node by index.
If remove is true, the returned nodes are removed If node is not found at specific rank, nil is returned
Time complexity: O(log(N))
func (*SortedSet) GetByKey ¶
func (ss *SortedSet) GetByKey(key string) *SortedSetNode
Get node by key
If node is not found, nil is returned Time complexity: O(1)
func (*SortedSet) GetRangeByIndex ¶
func (ss *SortedSet) GetRangeByIndex(start int, end int, options GetRangeOptions) []*SortedSetNode
GetRangeByIndex returns array of nodes within specific index range [start, end]. The given start and end must be a valid rank-based index which can be obtained from 'SanitizeRank'.
If start is greater than end, the returned array is in reserved order.
Time complexity: O(log(N)) with high probability
func (*SortedSet) GetRangeByLex ¶
func (ss *SortedSet) GetRangeByLex(start string, end string, options GetRangeOptions) []*SortedSetNode
GetRangeByLex returns an array of nodes that satisfy the given score range.
Time complexity: O(log(N))
func (*SortedSet) GetRangeByRank ¶
func (ss *SortedSet) GetRangeByRank(start int, end int, options GetRangeOptions) []*SortedSetNode
GetRangeByRank returns array of nodes within specific rank range [start, end]. If start is greater than end, returns an empty array.
Time complexity: O(log(N)) with high probability
func (*SortedSet) GetRangeByScore ¶
func (ss *SortedSet) GetRangeByScore(start float64, end float64, options GetRangeOptions) []*SortedSetNode
GetRangeByScore returns an array of nodes that satisfy the given score range.
Time complexity: O(log(N))
func (*SortedSet) PeekMax ¶
func (ss *SortedSet) PeekMax() *SortedSetNode
PeekMax returns the element with the highest score if it exists.
Time Complexity : O(1)
func (*SortedSet) PeekMin ¶
func (ss *SortedSet) PeekMin() *SortedSetNode
PeekMin returns the element with the lowest score if it exists. Otherwise it returns nil.
Time complexity: O(1)
func (*SortedSet) PopMax ¶
func (ss *SortedSet) PopMax() *SortedSetNode
PopMin returns the element with the highest score if it exists and removes it. Otherwise it returns nil.
Time complexity: O(log(N)) with high probability
func (*SortedSet) PopMin ¶
func (ss *SortedSet) PopMin() *SortedSetNode
PopMin returns the element with the lowest score if it exists and removes it. Otherwise it returns nil.
Time complexity: O(log(N)) with high probability
func (*SortedSet) Remove ¶
func (ss *SortedSet) Remove(key string) *SortedSetNode
Delete element specified by key
Time complexity: O(log(N)) with high probability
func (*SortedSet) RemoveByRank ¶
func (ss *SortedSet) RemoveByRank(rank int) *SortedSetNode
Delete element specified by rank
Time complexity: O(log(N)) with high probability
type SortedSetLevel ¶
type SortedSetLevel struct {
// contains filtered or unexported fields
}
type SortedSetNode ¶
type SortedSetNode struct { Key string // unique key of this node Score float64 // score to determine the order of this node in the set // contains filtered or unexported fields }
Node in skip list
type String ¶
type String struct {
// contains filtered or unexported fields
}
func StringUnmarshal ¶
type ZSet ¶
type ZSet struct {
// contains filtered or unexported fields
}
func NewZSetFromSs ¶
func ZSetUnmarshal ¶
func (*ZSet) FindNodeByLex ¶
func (ss *ZSet) FindNodeByLex(key string) (*SortedSetNode, int)
func (*ZSet) GetByKey ¶
func (ss *ZSet) GetByKey(key string) *SortedSetNode
func (*ZSet) GetRangeByRank ¶
func (ss *ZSet) GetRangeByRank(start int, end int, options GetRangeOptions) []*SortedSetNode
func (*ZSet) Remove ¶
func (ss *ZSet) Remove(key string) *SortedSetNode