Documentation ¶
Index ¶
- Variables
- type DataIndexMode
- type DataType
- type IOType
- type Options
- type RoseDB
- func (db *RoseDB) Append(key, value []byte) error
- func (db *RoseDB) Backup(path string) error
- func (db *RoseDB) Close() error
- func (db *RoseDB) Count() int
- func (db *RoseDB) Decr(key []byte) (int64, error)
- func (db *RoseDB) DecrBy(key []byte, decr int64) (int64, error)
- func (db *RoseDB) Delete(key []byte) error
- func (db *RoseDB) Get(key []byte) ([]byte, error)
- func (db *RoseDB) GetDel(key []byte) ([]byte, error)
- func (db *RoseDB) HDel(key []byte, fields ...[]byte) (int, error)
- func (db *RoseDB) HExists(key, field []byte) (bool, error)
- func (db *RoseDB) HGet(key, field []byte) ([]byte, error)
- func (db *RoseDB) HGetAll(key []byte) ([][]byte, error)
- func (db *RoseDB) HIncrBy(key, field []byte, incr int64) (int64, error)
- func (db *RoseDB) HKeys(key []byte) ([][]byte, error)
- func (db *RoseDB) HLen(key []byte) int
- func (db *RoseDB) HMGet(key []byte, fields ...[]byte) (vals [][]byte, err error)
- func (db *RoseDB) HScan(key []byte, prefix []byte, pattern string, count int) ([][]byte, error)
- func (db *RoseDB) HSet(key []byte, args ...[]byte) error
- func (db *RoseDB) HSetNX(key, field, value []byte) (bool, error)
- func (db *RoseDB) HStrLen(key, field []byte) int
- func (db *RoseDB) HVals(key []byte) ([][]byte, error)
- func (db *RoseDB) Incr(key []byte) (int64, error)
- func (db *RoseDB) IncrBy(key []byte, incr int64) (int64, error)
- func (db *RoseDB) LIndex(key []byte, index int) ([]byte, error)
- func (db *RoseDB) LLen(key []byte) int
- func (db *RoseDB) LMove(srcKey, dstKey []byte, srcIsLeft, dstIsLeft bool) ([]byte, error)
- func (db *RoseDB) LPop(key []byte) ([]byte, error)
- func (db *RoseDB) LPush(key []byte, values ...[]byte) error
- func (db *RoseDB) LPushX(key []byte, values ...[]byte) error
- func (db *RoseDB) LRange(key []byte, start, end int) (values [][]byte, err error)
- func (db *RoseDB) LSet(key []byte, index int, value []byte) error
- func (db *RoseDB) MGet(keys [][]byte) ([][]byte, error)
- func (db *RoseDB) MSet(args ...[]byte) error
- func (db *RoseDB) MSetNX(args ...[]byte) error
- func (db *RoseDB) RPop(key []byte) ([]byte, error)
- func (db *RoseDB) RPush(key []byte, values ...[]byte) error
- func (db *RoseDB) RPushX(key []byte, values ...[]byte) error
- func (db *RoseDB) RunLogFileGC(dataType DataType, fid int, gcRatio float64) error
- func (db *RoseDB) SAdd(key []byte, members ...[]byte) error
- func (db *RoseDB) SCard(key []byte) int
- func (db *RoseDB) SDiff(keys ...[]byte) ([][]byte, error)
- func (db *RoseDB) SIsMember(key, member []byte) bool
- func (db *RoseDB) SMembers(key []byte) ([][]byte, error)
- func (db *RoseDB) SPop(key []byte, count uint) ([][]byte, error)
- func (db *RoseDB) SRem(key []byte, members ...[]byte) error
- func (db *RoseDB) SUnion(keys ...[]byte) ([][]byte, error)
- func (db *RoseDB) Scan(prefix []byte, pattern string, count int) ([][]byte, error)
- func (db *RoseDB) Set(key, value []byte) error
- func (db *RoseDB) SetEX(key, value []byte, duration time.Duration) error
- func (db *RoseDB) SetNX(key, value []byte) error
- func (db *RoseDB) StrLen(key []byte) int
- func (db *RoseDB) Sync() error
- func (db *RoseDB) ZAdd(key []byte, score float64, member []byte) error
- func (db *RoseDB) ZCard(key []byte) int
- func (db *RoseDB) ZRange(key []byte, start, stop int) ([][]byte, error)
- func (db *RoseDB) ZRank(key []byte, member []byte) (ok bool, rank int)
- func (db *RoseDB) ZRem(key, member []byte) error
- func (db *RoseDB) ZRevRange(key []byte, start, stop int) ([][]byte, error)
- func (db *RoseDB) ZRevRank(key []byte, member []byte) (ok bool, rank int)
- func (db *RoseDB) ZScore(key, member []byte) (ok bool, score float64)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyNotFound key not found ErrKeyNotFound = errors.New("key not found") // ErrLogFileNotFound log file not found ErrLogFileNotFound = errors.New("log file not found") // ErrWrongNumberOfArgs doesn't match key-value pair numbers ErrWrongNumberOfArgs = errors.New("wrong number of arguments") // ErrIntegerOverflow overflows int64 limitations ErrIntegerOverflow = errors.New("increment or decrement overflow") // ErrWrongValueType value is not a number ErrWrongValueType = errors.New("value is not an integer") // ErrWrongIndex index is out of range ErrWrongIndex = errors.New("index is out of range") // ErrGCRunning log file gc is running ErrGCRunning = errors.New("log file gc is running, retry later") )
var ErrDiscardNoSpace = errors.New("not enough space can be allocated for the discard file")
ErrDiscardNoSpace no enough space for discard file.
Functions ¶
This section is empty.
Types ¶
type DataIndexMode ¶
type DataIndexMode int
DataIndexMode the data index mode.
const ( // KeyValueMemMode key and value are both in memory, read operation will be very fast in this mode. // Because there is no disk seek, just get value from the corresponding data structures in memory. // This mode is suitable for scenarios where the value are relatively small. KeyValueMemMode DataIndexMode = iota // KeyOnlyMemMode only key in memory, there is a disk seek while getting a value. // Because values are in log file on disk. KeyOnlyMemMode )
type IOType ¶
type IOType int8
IOType represents different types of file io: FileIO(standard file io) and MMap(Memory Map).
type Options ¶
type Options struct { // DBPath db path, will be created automatically if not exist. DBPath string // IndexMode mode of index, support KeyValueMemMode and KeyOnlyMemMode now. // Note that this mode is only for kv pairs, not List, Hash, Set, and ZSet. // Default value is KeyOnlyMemMode. IndexMode DataIndexMode // IoType file r/w io type, support FileIO and MMap now. // Default value is FileIO. IoType IOType // Sync is whether to sync writes from the OS buffer cache through to actual disk. // If false, and the machine crashes, then some recent writes may be lost. // Note that if it is just the process that crashes (and the machine does not) then no writes will be lost. // Default value is false. Sync bool // LogFileGCInterval a background goroutine will execute log file garbage collection periodically according to the interval. // It will pick the log file that meet the conditions for GC, then rewrite the valid data one by one. // Default value is 8 hours. LogFileGCInterval time.Duration // LogFileGCRatio if discarded data in log file exceeds this ratio, it can be picked up for compaction(garbage collection) // And if there are many files reached the ratio, we will pick the highest one by one. // The recommended ratio is 0.5, half of the file can be compacted. // Default value is 0.5. LogFileGCRatio float64 // LogFileSizeThreshold threshold size of each log file, active log file will be closed if reach the threshold. // Important!!! This option must be set to the same value as the first startup. // Default value is 512MB. LogFileSizeThreshold int64 // DiscardBufferSize a channel will be created to send the older entry size when a key updated or deleted. // Entry size will be saved in the discard file, recording the invalid size in a log file, and be used when log file gc is running. // This option represents the size of that channel. // If you got errors like `send discard chan fail`, you can increase this option to avoid it. DiscardBufferSize int }
Options for opening a db.
func DefaultOptions ¶
DefaultOptions default options for opening a RoseDB.
type RoseDB ¶
type RoseDB struct {
// contains filtered or unexported fields
}
RoseDB a db instance.
func (*RoseDB) Append ¶
Append appends the value at the end of the old value if key already exists. It will be similar to Set if key does not exist.
func (*RoseDB) Backup ¶ added in v1.1.1
Backup copies the db directory to the given path for backup. It will create the path if it does not exist.
func (*RoseDB) Decr ¶
Decr decrements the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. It returns ErrWrongKeyType error if the value is not integer type. Also, it returns ErrIntegerOverflow error if the value exceeds after decrementing the value.
func (*RoseDB) DecrBy ¶
DecrBy decrements the number stored at key by decr. If the key doesn't exist, it is set to 0 before performing the operation. It returns ErrWrongKeyType error if the value is not integer type. Also, it returns ErrIntegerOverflow error if the value exceeds after decrementing the value.
func (*RoseDB) Get ¶
Get get the value of key. If the key does not exist the error ErrKeyNotFound is returned.
func (*RoseDB) GetDel ¶
GetDel gets the value of the key and deletes the key. This method is similar to Get method. It also deletes the key if it exists.
func (*RoseDB) HDel ¶
HDel removes the specified fields from the hash stored at key. Specified fields that do not exist within this hash are ignored. If key does not exist, it is treated as an empty hash and this command returns false.
func (*RoseDB) HExists ¶
HExists returns whether the field exists in the hash stored at key. If the hash contains field, it returns true. If the hash does not contain field, or key does not exist, it returns false.
func (*RoseDB) HIncrBy ¶ added in v1.1.0
HIncrBy increments the number stored at field in the hash stored at key by increment. If key does not exist, a new key holding a hash is created. If field does not exist the value is set to 0 before the operation is performed. The range of values supported by HINCRBY is limited to 64bit signed integers.
func (*RoseDB) HMGet ¶ added in v1.1.0
HMGet returns the values associated with the specified fields in the hash stored at the key. For every field that does not exist in the hash, a nil value is returned. Because non-existing keys are treated as empty hashes, running HMGET against a non-existing key will return a list of nil values.
func (*RoseDB) HScan ¶ added in v1.1.0
HScan iterates over a specified key of type Hash and finds its fields and values. Parameter prefix will match field`s prefix, and pattern is a regular expression that also matchs the field. Parameter count limits the number of keys, a nil slice will be returned if count is not a positive number. The returned values will be a mixed data of fields and values, like [field1, value1, field2, value2, etc...].
func (*RoseDB) HSet ¶
HSet sets field in the hash stored at key to value. If key does not exist, a new key holding a hash is created. If field already exists in the hash, it is overwritten. Return num of elements in hash of the specified key. Multiple field-value pair is accepted. Parameter order should be like "key", "field", "value", "field", "value"...
func (*RoseDB) HSetNX ¶ added in v1.1.0
HSetNX sets the given value only if the field doesn't exist. If the key doesn't exist, new hash is created. If field already exist, HSetNX doesn't have side effect.
func (*RoseDB) HStrLen ¶
HStrLen returns the string length of the value associated with field in the hash stored at key. If the key or the field do not exist, 0 is returned.
func (*RoseDB) Incr ¶
Incr increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. It returns ErrWrongKeyType error if the value is not integer type. Also, it returns ErrIntegerOverflow error if the value exceeds after incrementing the value.
func (*RoseDB) IncrBy ¶
IncrBy increments the number stored at key by incr. If the key doesn't exist, it is set to 0 before performing the operation. It returns ErrWrongKeyType error if the value is not integer type. Also, it returns ErrIntegerOverflow error if the value exceeds after incrementing the value.
func (*RoseDB) LIndex ¶ added in v1.1.0
LIndex returns the element at index in the list stored at key. If index is out of range, it returns nil.
func (*RoseDB) LLen ¶
LLen returns the length of the list stored at key. If key does not exist, it is interpreted as an empty list and 0 is returned.
func (*RoseDB) LMove ¶ added in v1.1.0
LMove atomically returns and removes the first/last element of the list stored at source, and pushes the element at the first/last element of the list stored at destination.
func (*RoseDB) LPush ¶
LPush insert all the specified values at the head of the list stored at key. If key does not exist, it is created as empty list before performing the push operations.
func (*RoseDB) LPushX ¶ added in v1.1.0
LPushX insert specified values at the head of the list stored at key, only if key already exists and holds a list. In contrary to LPUSH, no operation will be performed when key does not yet exist.
func (*RoseDB) LRange ¶ added in v1.1.0
LRange returns the specified elements of the list stored at key. The offsets start and stop are zero-based indexes, with 0 being the first element of the list (the head of the list), 1 being the next element and so on. These offsets can also be negative numbers indicating offsets starting at the end of the list. For example, -1 is the last element of the list, -2 the penultimate, and so on. If start is larger than the end of the list, an empty list is returned. If stop is larger than the actual end of the list, Redis will treat it like the last element of the list.
func (*RoseDB) MGet ¶
MGet get the values of all specified keys. If the key that does not hold a string value or does not exist, nil is returned.
func (*RoseDB) MSet ¶
MSet is multiple set command. Parameter order should be like "key", "value", "key", "value", ...
func (*RoseDB) MSetNX ¶
MSetNX sets given keys to their respective values. MSetNX will not perform any operation at all even if just a single key already exists.
func (*RoseDB) RPush ¶
RPush insert all the specified values at the tail of the list stored at key. If key does not exist, it is created as empty list before performing the push operation.
func (*RoseDB) RPushX ¶ added in v1.1.0
RPushX insert specified values at the tail of the list stored at key, only if key already exists and holds a list. In contrary to RPUSH, no operation will be performed when key does not yet exist.
func (*RoseDB) RunLogFileGC ¶
RunLogFileGC run log file garbage collection manually.
func (*RoseDB) SAdd ¶
SAdd add the specified members to the set stored at key. Specified members that are already a member of this set are ignored. If key does not exist, a new set is created before adding the specified members.
func (*RoseDB) SCard ¶
SCard returns the set cardinality (number of elements) of the set stored at key.
func (*RoseDB) SDiff ¶
SDiff returns the members of the set difference between the first set and all the successive sets. Returns error if no key is passed as a parameter.
func (*RoseDB) SPop ¶
SPop removes and returns one or more random members from the set value store at key.
func (*RoseDB) SRem ¶
SRem remove the specified members from the set stored at key. Specified members that are not a member of this set are ignored. If key does not exist, it is treated as an empty set and this command returns 0.
func (*RoseDB) SUnion ¶
SUnion returns the members of the set resulting from the union of all the given sets.
func (*RoseDB) Scan ¶ added in v1.1.0
Scan iterates over all keys of type String and finds its value. Parameter prefix will match key`s prefix, and pattern is a regular expression that also matchs the key. Parameter count limits the number of keys, a nil slice will be returned if count is not a positive number. The returned values will be a mixed data of keys and values, like [key1, value1, key2, value2, etc...].
func (*RoseDB) Set ¶
Set set key to hold the string value. If key already holds a value, it is overwritten. Any previous time to live associated with the key is discarded on successful Set operation.
func (*RoseDB) SetEX ¶
SetEX set key to hold the string value and set key to timeout after the given duration.
func (*RoseDB) SetNX ¶
SetNX sets the key-value pair if it is not exist. It returns nil if the key already exists.
func (*RoseDB) StrLen ¶
StrLen returns the length of the string value stored at key. If the key doesn't exist, it returns 0.
func (*RoseDB) ZAdd ¶
ZAdd adds the specified member with the specified score to the sorted set stored at key.
func (*RoseDB) ZCard ¶
ZCard returns the sorted set cardinality (number of elements) of the sorted set stored at key.
func (*RoseDB) ZRange ¶
ZRange returns the specified range of elements in the sorted set stored at key.
func (*RoseDB) ZRank ¶ added in v1.1.1
ZRank returns the rank of member in the sorted set stored at key, with the scores ordered from low to high. The rank (or index) is 0-based, which means that the member with the lowest score has rank 0.
func (*RoseDB) ZRem ¶
ZRem removes the specified members from the sorted set stored at key. Non existing members are ignored. An error is returned when key exists and does not hold a sorted set.
func (*RoseDB) ZRevRange ¶ added in v1.1.1
ZRevRange returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the highest to the lowest score.