Documentation
¶
Index ¶
- type ConcurrentDict
- func (dict *ConcurrentDict) Clear()
- func (dict *ConcurrentDict) DictScan(cursor int, count int, pattern string) ([][]byte, int)
- func (dict *ConcurrentDict) ForEach(consumer Consumer)
- func (dict *ConcurrentDict) Get(key string) (val interface{}, exists bool)
- func (dict *ConcurrentDict) GetWithLock(key string) (val interface{}, exists bool)
- func (dict *ConcurrentDict) Keys() []string
- func (dict *ConcurrentDict) Len() int
- func (dict *ConcurrentDict) Put(key string, val interface{}) (result int)
- func (dict *ConcurrentDict) PutIfAbsent(key string, val interface{}) (result int)
- func (dict *ConcurrentDict) PutIfAbsentWithLock(key string, val interface{}) (result int)
- func (dict *ConcurrentDict) PutIfExists(key string, val interface{}) (result int)
- func (dict *ConcurrentDict) PutIfExistsWithLock(key string, val interface{}) (result int)
- func (dict *ConcurrentDict) PutWithLock(key string, val interface{}) (result int)
- func (dict *ConcurrentDict) RWLocks(writeKeys []string, readKeys []string)
- func (dict *ConcurrentDict) RWUnLocks(writeKeys []string, readKeys []string)
- func (dict *ConcurrentDict) RandomDistinctKeys(limit int) []string
- func (dict *ConcurrentDict) RandomKeys(limit int) []string
- func (dict *ConcurrentDict) Remove(key string) (val interface{}, result int)
- func (dict *ConcurrentDict) RemoveWithLock(key string) (val interface{}, result int)
- type Consumer
- type Dict
- type SimpleDict
- func (dict *SimpleDict) Clear()
- func (dict *SimpleDict) DictScan(cursor int, count int, pattern string) ([][]byte, int)
- func (dict *SimpleDict) ForEach(consumer Consumer)
- func (dict *SimpleDict) Get(key string) (val interface{}, exists bool)
- func (dict *SimpleDict) Keys() []string
- func (dict *SimpleDict) Len() int
- func (dict *SimpleDict) Put(key string, val interface{}) (result int)
- func (dict *SimpleDict) PutIfAbsent(key string, val interface{}) (result int)
- func (dict *SimpleDict) PutIfExists(key string, val interface{}) (result int)
- func (dict *SimpleDict) RandomDistinctKeys(limit int) []string
- func (dict *SimpleDict) RandomKeys(limit int) []string
- func (dict *SimpleDict) Remove(key string) (val interface{}, result int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentDict ¶
type ConcurrentDict struct {
// contains filtered or unexported fields
}
ConcurrentDict is thread safe map using sharding lock
func MakeConcurrent ¶
func MakeConcurrent(shardCount int) *ConcurrentDict
MakeConcurrent creates ConcurrentDict with the given shard count
func (*ConcurrentDict) ForEach ¶
func (dict *ConcurrentDict) ForEach(consumer Consumer)
ForEach traversal the dict it may not visit new entry inserted during traversal
func (*ConcurrentDict) Get ¶
func (dict *ConcurrentDict) Get(key string) (val interface{}, exists bool)
Get returns the binding value and whether the key is exist
func (*ConcurrentDict) GetWithLock ¶
func (dict *ConcurrentDict) GetWithLock(key string) (val interface{}, exists bool)
func (*ConcurrentDict) Keys ¶
func (dict *ConcurrentDict) Keys() []string
Keys returns all keys in dict
func (*ConcurrentDict) Put ¶
func (dict *ConcurrentDict) Put(key string, val interface{}) (result int)
Put puts key value into dict and returns the number of new inserted key-value
func (*ConcurrentDict) PutIfAbsent ¶
func (dict *ConcurrentDict) PutIfAbsent(key string, val interface{}) (result int)
PutIfAbsent puts value if the key is not exists and returns the number of updated key-value
func (*ConcurrentDict) PutIfAbsentWithLock ¶
func (dict *ConcurrentDict) PutIfAbsentWithLock(key string, val interface{}) (result int)
func (*ConcurrentDict) PutIfExists ¶
func (dict *ConcurrentDict) PutIfExists(key string, val interface{}) (result int)
PutIfExists puts value if the key is existed and returns the number of inserted key-value
func (*ConcurrentDict) PutIfExistsWithLock ¶
func (dict *ConcurrentDict) PutIfExistsWithLock(key string, val interface{}) (result int)
func (*ConcurrentDict) PutWithLock ¶
func (dict *ConcurrentDict) PutWithLock(key string, val interface{}) (result int)
func (*ConcurrentDict) RWLocks ¶
func (dict *ConcurrentDict) RWLocks(writeKeys []string, readKeys []string)
RWLocks locks write keys and read keys together. allow duplicate keys
func (*ConcurrentDict) RWUnLocks ¶
func (dict *ConcurrentDict) RWUnLocks(writeKeys []string, readKeys []string)
RWUnLocks unlocks write keys and read keys together. allow duplicate keys
func (*ConcurrentDict) RandomDistinctKeys ¶
func (dict *ConcurrentDict) RandomDistinctKeys(limit int) []string
RandomDistinctKeys randomly returns keys of the given number, won't contain duplicated key
func (*ConcurrentDict) RandomKeys ¶
func (dict *ConcurrentDict) RandomKeys(limit int) []string
RandomKeys randomly returns keys of the given number, may contain duplicated key
func (*ConcurrentDict) Remove ¶
func (dict *ConcurrentDict) Remove(key string) (val interface{}, result int)
Remove removes the key and return the number of deleted key-value
func (*ConcurrentDict) RemoveWithLock ¶
func (dict *ConcurrentDict) RemoveWithLock(key string) (val interface{}, result int)
type Dict ¶
type Dict interface { Get(key string) (val interface{}, exists bool) Len() int Put(key string, val interface{}) (result int) PutIfAbsent(key string, val interface{}) (result int) PutIfExists(key string, val interface{}) (result int) Remove(key string) (val interface{}, result int) ForEach(consumer Consumer) Keys() []string RandomKeys(limit int) []string RandomDistinctKeys(limit int) []string Clear() DictScan(cursor int, count int, pattern string) ([][]byte, int) }
Dict is interface of a key-value data structure
type SimpleDict ¶
type SimpleDict struct {
// contains filtered or unexported fields
}
SimpleDict wraps a map, it is not thread safe
func (*SimpleDict) ForEach ¶
func (dict *SimpleDict) ForEach(consumer Consumer)
ForEach traversal the dict
func (*SimpleDict) Get ¶
func (dict *SimpleDict) Get(key string) (val interface{}, exists bool)
Get returns the binding value and whether the key is exist
func (*SimpleDict) Put ¶
func (dict *SimpleDict) Put(key string, val interface{}) (result int)
Put puts key value into dict and returns the number of new inserted key-value
func (*SimpleDict) PutIfAbsent ¶
func (dict *SimpleDict) PutIfAbsent(key string, val interface{}) (result int)
PutIfAbsent puts value if the key is not exists and returns the number of updated key-value
func (*SimpleDict) PutIfExists ¶
func (dict *SimpleDict) PutIfExists(key string, val interface{}) (result int)
PutIfExists puts value if the key is existed and returns the number of inserted key-value
func (*SimpleDict) RandomDistinctKeys ¶
func (dict *SimpleDict) RandomDistinctKeys(limit int) []string
RandomDistinctKeys randomly returns keys of the given number, won't contain duplicated key
func (*SimpleDict) RandomKeys ¶
func (dict *SimpleDict) RandomKeys(limit int) []string
RandomKeys randomly returns keys of the given number, may contain duplicated key
func (*SimpleDict) Remove ¶
func (dict *SimpleDict) Remove(key string) (val interface{}, result int)
Remove removes the key and return the number of deleted key-value