Documentation
¶
Index ¶
- Variables
- type DataStructure
- type ListStructure
- func (l *ListStructure) LIndex(key []byte, index int) ([]byte, error)
- func (l *ListStructure) LLen(key []byte) (int, error)
- func (l *ListStructure) LPop(key []byte) ([]byte, error)
- func (l *ListStructure) LPush(key []byte, value []byte) error
- func (l *ListStructure) LPushs(key []byte, values ...[]byte) error
- func (l *ListStructure) LRange(key []byte, start int, stop int) ([][]byte, error)
- func (l *ListStructure) LRem(key []byte, count int, value []byte) error
- func (l *ListStructure) LSet(key []byte, index int, value []byte) error
- func (l *ListStructure) LTrim(key []byte, start int, stop int) error
- func (l *ListStructure) RPOPLPUSH(source []byte, destination []byte) error
- func (l *ListStructure) RPop(key []byte) ([]byte, error)
- func (l *ListStructure) RPush(key []byte, value []byte) error
- func (l *ListStructure) RPushs(key []byte, values ...[]byte) error
- type StringStructure
- func (s *StringStructure) Append(key, value []byte, ttl time.Duration) error
- func (s *StringStructure) Decr(key []byte, ttl time.Duration) error
- func (s *StringStructure) DecrBy(key []byte, amount int, ttl time.Duration) error
- func (s *StringStructure) Del(key []byte) error
- func (s *StringStructure) Exists(key []byte) (bool, error)
- func (s *StringStructure) Expire(key []byte, ttl time.Duration) error
- func (s *StringStructure) Get(key []byte) ([]byte, error)
- func (s *StringStructure) GetSet(key, value []byte, ttl time.Duration) ([]byte, error)
- func (s *StringStructure) Incr(key []byte, ttl time.Duration) error
- func (s *StringStructure) IncrBy(key []byte, amount int, ttl time.Duration) error
- func (s *StringStructure) IncrByFloat(key []byte, amount float64, ttl time.Duration) error
- func (s *StringStructure) Persist(key []byte) error
- func (s *StringStructure) Set(key, value []byte, ttl time.Duration) error
- func (s *StringStructure) StrLen(key []byte) (int, error)
- func (s *StringStructure) Type(key []byte) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrListEmpty is returned if the list is empty. ErrListEmpty = errors.New("Wrong operation: list is empty") // ErrIndexOutOfRange is returned if the index out of range. ErrIndexOutOfRange = errors.New("Wrong operation: index out of range") )
var ( // ErrInvalidValue is returned if the value is invalid. ErrInvalidValue = errors.New("Wrong value: invalid value") // ErrInvalidType is returned if the type is invalid. ErrInvalidType = errors.New("Wrong value: invalid type") // ErrKeyExpired is returned if the key is expired. ErrKeyExpired = errors.New("Wrong value: key expired") )
var ( // ErrWrongNumberOfArguments is returned when the number of arguments is wrong ErrWrongNumberOfArguments = errors.New("wrong number of arguments") )
Functions ¶
This section is empty.
Types ¶
type DataStructure ¶
type DataStructure = byte
const ( // String is a string data structure String DataStructure = iota + 1 // Hash is a hash data structure Hash // List is a list data structure List DataStructure = iota + 1 // Set is a set data structure Set // ZSet is a zset data structure ZSet // bitmap is a bitmap data structure Bitmap // Stream is a stream data structure Stream // Expire is a expire data structure Expire )
type ListStructure ¶
type ListStructure struct {
// contains filtered or unexported fields
}
Due to the complexity of each operation is at least O(n) So we can directly use slice to implement the list at the bottom level If the implementation of the db is improved later, we need to switch to a linked list
func NewListStructure ¶
func NewListStructure(options config.Options) (*ListStructure, error)
NewListStructure returns a new ListStructure It will return a nil ListStructure if the database cannot be opened or the database cannot be created The database will be created if it does not exist
func (*ListStructure) LIndex ¶
func (l *ListStructure) LIndex(key []byte, index int) ([]byte, error)
LIndex returns the value of an element in a list associated with a key based on the index. If the key does not exist, an error is returned. If the list is empty, an error is returned. Negative indices can be used, where -1 represents the last element of the list, -2 represents the second last element, and so on.
func (*ListStructure) LLen ¶
func (l *ListStructure) LLen(key []byte) (int, error)
LLen returns the size of a list associated with a key. If the key does not exist, an error is returned.
func (*ListStructure) LPop ¶
func (l *ListStructure) LPop(key []byte) ([]byte, error)
LPop returns and removes the leftmost value of a list associated with a key. If the key does not exist, an error is returned. If the list is empty, an error is returned.
func (*ListStructure) LPush ¶
func (l *ListStructure) LPush(key []byte, value []byte) error
LPush adds a value to the left of the list corresponding to the key If the key does not exist, it will create the key
func (*ListStructure) LPushs ¶
func (l *ListStructure) LPushs(key []byte, values ...[]byte) error
LPushs adds one or more values to the left of the list corresponding to the key If the key does not exist, it will create the key
func (*ListStructure) LRange ¶
LRange returns a range of elements from a list associated with a key. The range is inclusive, including both the start and stop indices. If the key does not exist, an error is returned. If the list is empty, an error is returned. Negative indices can be used, where -1 represents the last element of the list, -2 represents the second last element, and so on.
func (*ListStructure) LRem ¶
func (l *ListStructure) LRem(key []byte, count int, value []byte) error
LRem removes elements from a list associated with a key based on the count and value parameters. The count can have the following values: count > 0: Remove count occurrences of the value from the beginning of the list. count < 0: Remove count occurrences of the value from the end of the list. count = 0: Remove all occurrences of the value from the list. If the key does not exist, an error is returned.
func (*ListStructure) LSet ¶
func (l *ListStructure) LSet(key []byte, index int, value []byte) error
LSet sets the value of an element in a list associated with a key based on the index. If the index is out of range, an error is returned. If the list is empty, an error is returned.
func (*ListStructure) LTrim ¶
func (l *ListStructure) LTrim(key []byte, start int, stop int) error
LTrim retains a range of elements in a list associated with a key. The range is inclusive, including both the start and stop indices. If the key does not exist, an error is returned. If the list is empty, an error is returned. Negative indices can be used, where -1 represents the last element of the list, -2 represents the second last element, and so on.
func (*ListStructure) RPOPLPUSH ¶
func (l *ListStructure) RPOPLPUSH(source []byte, destination []byte) error
RPOPLPUSH removes the last element from one list and pushes it to another list. If the source list is empty, an error is returned. If the destination list is empty, it is created. Atomicity is not guaranteed.
func (*ListStructure) RPop ¶
func (l *ListStructure) RPop(key []byte) ([]byte, error)
RPop returns and removes the rightmost value of a list associated with a key. If the key does not exist, an error is returned. If the list is empty, an error is returned.
type StringStructure ¶
type StringStructure struct {
// contains filtered or unexported fields
}
StringStructure is a structure that stores string data
func NewStringStructure ¶
func NewStringStructure(options config.Options) (*StringStructure, error)
NewStringStructure returns a new StringStructure It will return a nil StringStructure if the database cannot be opened or the database cannot be created The database will be created if it does not exist
func (*StringStructure) Append ¶
func (s *StringStructure) Append(key, value []byte, ttl time.Duration) error
Append appends a value to the value of a key
func (*StringStructure) Decr ¶
func (s *StringStructure) Decr(key []byte, ttl time.Duration) error
Decr decrements the integer value of a key by 1
func (*StringStructure) Del ¶
func (s *StringStructure) Del(key []byte) error
Del deletes the value of a key If the key does not exist, it will return nil If the key exists, it will be deleted If the key is expired, it will be deleted and return nil If the key is not expired, it will be updated and return nil
func (*StringStructure) Exists ¶
func (s *StringStructure) Exists(key []byte) (bool, error)
Exists checks if a key exists
func (*StringStructure) Expire ¶
func (s *StringStructure) Expire(key []byte, ttl time.Duration) error
Expire sets the expiration time of a key
func (*StringStructure) Get ¶
func (s *StringStructure) Get(key []byte) ([]byte, error)
Get gets the value of a key If the key does not exist, it will return nil If the key exists, it will return the value If the key is expired, it will be deleted and return nil If the key is not expired, it will be updated and return the value
func (*StringStructure) Incr ¶
func (s *StringStructure) Incr(key []byte, ttl time.Duration) error
Incr increments the integer value of a key by 1
func (*StringStructure) IncrByFloat ¶
IncrByFloat increments the float value of a key by the given amount
func (*StringStructure) Persist ¶
func (s *StringStructure) Persist(key []byte) error
Persist removes the expiration time of a key
func (*StringStructure) Set ¶
func (s *StringStructure) Set(key, value []byte, ttl time.Duration) error
Set sets the value of a key If the key does not exist, it will be created If the key exists, it will be overwritten If the key is expired, it will be deleted If the key is not expired, it will be updated
func (*StringStructure) StrLen ¶
func (s *StringStructure) StrLen(key []byte) (int, error)
StrLen returns the length of the value of a key If the key does not exist, it will return 0 If the key exists, it will return the length of the value If the key is expired, it will be deleted and return 0 If the key is not expired, it will be updated and return the length of the value
func (*StringStructure) Type ¶
func (s *StringStructure) Type(key []byte) (string, error)
Type returns the type of a key If the key does not exist, it will return "" If the key exists, it will return "string" If the key is expired, it will be deleted and return "" If the key is not expired, it will be updated and return "string"