structure

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: Apache-2.0 Imports: 9 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")
)

Functions

This section is empty.

Types

type BitOperation added in v1.0.7

type BitOperation string

BitOperation is a type used to define the operations that can be performed on bits

const (
	// BitAndOperation performs the AND operation.
	BitAndOperation BitOperation = "AND"
	// BitOrOperation performs the OR operation.
	BitOrOperation BitOperation = "OR"
	// BitXorOperation performs the XOR operation.
	BitXorOperation BitOperation = "XOR"
	// BitNotOperation performs the NOT operation.
	BitNotOperation BitOperation = "NOT"
)

Constants representing the different bit operations

type BitSet added in v1.0.7

type BitSet struct {
	// contains filtered or unexported fields
}

BitSet is a structure that holds a reference to a BitSet

func (*BitSet) At added in v1.0.7

func (b *BitSet) At(pos uint) bool

At function checks if the bit at the specified position is set

func (*BitSet) Next added in v1.0.7

func (b *BitSet) Next(pos uint) (uint, bool)

Next function finds the next set bit in the bitset

type BitmapStructure added in v1.0.7

type BitmapStructure struct {
	// contains filtered or unexported fields
}

BitmapStructure is a structure that holds a reference to the database engine

func NewBitmap added in v1.0.7

func NewBitmap(options config.Options) (*BitmapStructure, error)

NewBitmap function initializes a new BitmapStructure with the provided options

func (*BitmapStructure) BitCount added in v1.0.7

func (b *BitmapStructure) BitCount(k string, start, end uint) (uint, error)

BitCount function counts the number of set bits in the specified range in the bitmap for the provided key

func (*BitmapStructure) BitOp added in v1.0.7

func (b *BitmapStructure) BitOp(op BitOperation, destKey string, keys ...string) error

BitOp function performs the specified bit operation on the provided keys and stores the result in the destination key

func (*BitmapStructure) DelBit added in v1.0.7

func (b *BitmapStructure) DelBit(k string, off uint) error

DelBit function deletes a bit at the specified offset in the bitmap for the provided key

func (*BitmapStructure) DelBits added in v1.0.7

func (b *BitmapStructure) DelBits(k string, off ...uint) error

DelBits function deletes multiple bits at the specified offsets in the bitmap for the provided key

func (*BitmapStructure) GetBit added in v1.0.7

func (b *BitmapStructure) GetBit(k string, off uint) (bool, error)

GetBit function retrieves a bit at the specified offset in the bitmap for the provided key

func (*BitmapStructure) GetBits added in v1.0.7

func (b *BitmapStructure) GetBits(k string) (*BitSet, error)

GetBits function retrieves the bits for the provided key

func (*BitmapStructure) SetBit added in v1.0.7

func (b *BitmapStructure) SetBit(k string, off uint) error

SetBit function sets a bit at the specified offset in the bitmap for the provided key

func (*BitmapStructure) SetBits added in v1.0.7

func (b *BitmapStructure) SetBits(k string, off ...uint) error

SetBits function sets multiple bits at the specified offsets in the bitmap for the provided key

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
	// 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 HashField added in v1.0.6

type HashField struct {
	// contains filtered or unexported fields
}

type HashMetadata added in v1.0.6

type HashMetadata struct {
	// contains filtered or unexported fields
}

type HashStructure added in v1.0.6

type HashStructure struct {
	// contains filtered or unexported fields
}

func NewHashStructure added in v1.0.6

func NewHashStructure(options config.Options) (*HashStructure, error)

NewHashStructure Returns a new NewHashStructure

func (*HashStructure) HDecrBy added in v1.0.6

func (hs *HashStructure) HDecrBy(k string, f interface{}, decrement int64) (int64, error)

HDecrBy decrements the integer value of a hash field by the given number.

func (*HashStructure) HDel added in v1.0.6

func (hs *HashStructure) HDel(k string, f interface{}) (bool, error)

HDel deletes one field from a hash.

func (*HashStructure) HExists added in v1.0.6

func (hs *HashStructure) HExists(k string, f interface{}) (bool, error)

HExists determines whether a hash field exists or not.

func (*HashStructure) HGet added in v1.0.6

func (hs *HashStructure) HGet(k string, f interface{}) (interface{}, error)

HGet gets the string value of a hash field.

func (*HashStructure) HIncrBy added in v1.0.6

func (hs *HashStructure) HIncrBy(k string, f interface{}, increment int64) (int64, error)

HIncrBy increments the integer value of a hash field by the given number.

func (*HashStructure) HIncrByFloat added in v1.0.6

func (hs *HashStructure) HIncrByFloat(k string, f interface{}, increment float64) (float64, error)

HIncrByFloat increments the float value of a hash field by the given number.

func (*HashStructure) HLen added in v1.0.6

func (hs *HashStructure) HLen(k string) (int, error)

HLen gets the number of fields contained in a hash.

func (*HashStructure) HMGet added in v1.0.7

func (hs *HashStructure) HMGet(k string, f ...interface{}) ([]interface{}, error)

HMGet gets the string value of a hash field.

func (*HashStructure) HMove added in v1.0.6

func (hs *HashStructure) HMove(source, destination string, f interface{}) (bool, error)

HMove moves field from the hash stored at source to the hash stored at destination.

func (*HashStructure) HSet added in v1.0.6

func (hs *HashStructure) HSet(k string, f, v interface{}) (bool, error)

HSet sets the string value of a hash field.

func (*HashStructure) HSetNX added in v1.0.6

func (hs *HashStructure) HSetNX(k string, f, v interface{}) (bool, error)

HSetNX sets field in the hash stored at key to value, only if field does not yet exist.

func (*HashStructure) HStrLen added in v1.0.6

func (hs *HashStructure) HStrLen(k string, f interface{}) (int, error)

HStrLen returns the string length of the value associated with field in the hash stored at key.

func (*HashStructure) HTypes added in v1.0.6

func (hs *HashStructure) HTypes(k string, f interface{}) (string, error)

HTypes returns if field is an existing hash key in the hash stored at key.

func (*HashStructure) HUpdate added in v1.0.6

func (hs *HashStructure) HUpdate(k string, f, v interface{}) (bool, error)

HUpdate updates the string value of a hash field.

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 string, v interface{}, ttl time.Duration) error

Append appends a value to the value of a key

func (*StringStructure) Clean added in v1.0.7

func (s *StringStructure) Clean()

func (*StringStructure) Decr

func (s *StringStructure) Decr(key string, ttl time.Duration) error

Decr decrements the integer value of a key by 1

func (*StringStructure) DecrBy

func (s *StringStructure) DecrBy(key string, 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(k string) 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 string) (bool, error)

Exists checks if a key exists

func (*StringStructure) Expire

func (s *StringStructure) Expire(key string, ttl time.Duration) error

Expire sets the expiration time of a key

func (*StringStructure) Get

func (s *StringStructure) Get(k string) (interface{}, 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 string, value interface{}, ttl time.Duration) (interface{}, error)

GetSet sets the value of a key and returns its old value

func (*StringStructure) Incr

func (s *StringStructure) Incr(key string, ttl time.Duration) error

Incr increments the integer value of a key by 1

func (*StringStructure) IncrBy

func (s *StringStructure) IncrBy(key string, 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 string, 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 string) error

Persist removes the expiration time of a key

func (*StringStructure) Set

func (s *StringStructure) Set(k string, v interface{}, 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 (s *StringStructure) Set(key, value []byte, ttl time.Duration) error {

func (*StringStructure) Stop added in v1.0.7

func (s *StringStructure) Stop() error

func (*StringStructure) StrLen

func (s *StringStructure) StrLen(k string) (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(k string) (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