structure

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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")
)
View Source
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

func (l *ListStructure) LRange(key []byte, start int, stop int) ([][]byte, error)

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.

func (*ListStructure) RPush

func (l *ListStructure) RPush(key []byte, value []byte) error

RPush adds a value to the right of the list corresponding to the key If the key does not exist, it will create the key

func (*ListStructure) RPushs

func (l *ListStructure) RPushs(key []byte, values ...[]byte) error

RPushs appends one or more values to the right side of a list associated with a key. If the key does not exist, it will be created.

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) DecrBy

func (s *StringStructure) DecrBy(key []byte, amount int, ttl time.Duration) error

DecrBy decrements the integer value of a key by the given amount

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) GetSet

func (s *StringStructure) GetSet(key, value []byte, ttl time.Duration) ([]byte, error)

GetSet sets the value of a key and returns its old 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) IncrBy

func (s *StringStructure) IncrBy(key []byte, amount int, ttl time.Duration) error

IncrBy increments the integer value of a key by the given amount

func (*StringStructure) IncrByFloat

func (s *StringStructure) IncrByFloat(key []byte, amount float64, ttl time.Duration) error

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"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL