eval

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: BSD-3-Clause Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BYTE = "BYTE"
	BIT  = "BIT"

	AND string = "AND"
	OR  string = "OR"
	XOR string = "XOR"
	NOT string = "NOT"

	Ex              string = "EX"
	Px              string = "PX"
	Persist         string = "PERSIST"
	Pxat            string = "PXAT"
	Exat            string = "EXAT"
	XX              string = "XX"
	NX              string = "NX"
	GT              string = "GT"
	LT              string = "LT"
	CH              string = "CH"
	INCR            string = "INCR"
	KeepTTL         string = "KEEPTTL"
	Sync            string = "SYNC"
	Async           string = "ASYNC"
	Help            string = "HELP"
	Memory          string = "MEMORY"
	Count           string = "COUNT"
	GetKeys         string = "GETKEYS"
	GetKeysandFlags string = "GETKEYSANDFLAGS"
	List            string = "LIST"
	Info            string = "INFO"
	Docs            string = "DOCS"

	WithValues string = "WITHVALUES"
	WithScores string = "WITHSCORES"
	WithScore  string = "WITHSCORE"
	REV        string = "REV"
	GET        string = "GET"
	SET        string = "SET"
	INCRBY     string = "INCRBY"
	OVERFLOW   string = "OVERFLOW"
	WRAP       string = "WRAP"
	SAT        string = "SAT"
	FAIL       string = "FAIL"
	SIGNED     string = "SIGNED"
	UNSIGNED   string = "UNSIGNED"
	CAPACITY   string = "CAPACITY"
	SIZE       string = "SIZE"
	FILTERS    string = "FILTER"
	ITEMS      string = "ITEMS"
	EXPANSION  string = "EXPANSION"
)
View Source
const (
	Before = "before"
	After  = "after"
)
View Source
const (
	Uninitialized exDurationState = iota
	Initialized
)
View Source
const (
	IncrBy = "INCRBY"
	MultBy = "MULTBY"
)
View Source
const (
	CountConst = "COUNT"
)

Variables

View Source
var (
	PreProcessing = map[string]func([]string, *dstore.Store) *EvalResponse{}
	DiceCmds      = map[string]DiceCmdMeta{}
)
View Source
var ErrDequeEmpty = errors.New("deque is empty")
View Source
var RespEmptyArray = []byte("*0\r\n")
View Source
var RespMinusOne = []byte(":-1\r\n")
View Source
var RespMinusTwo = []byte(":-2\r\n")
View Source
var RespNIL = []byte("$-1\r\n")
View Source
var RespOK = []byte("+OK\r\n")
View Source
var RespOne = []byte(":1\r\n")
View Source
var RespQueued = []byte("+QUEUED\r\n")
View Source
var RespZero = []byte(":0\r\n")
View Source
var (
	TxnCommands map[string]bool
)

Functions

func ByteSliceToByteArrayObj

func ByteSliceToByteArrayObj(store *dstore.Store, oldObj *object.Obj, b []byte) (*object.Obj, error)

ByteSliceToByteArrayObj converts a byte slice to an Obj with a ByteArray value

func ByteSliceToIntObj

func ByteSliceToIntObj(store *dstore.Store, oldObj *object.Obj, b []byte) (*object.Obj, error)

ByteSliceToIntObj converts a byte slice to an Obj with an integer value

func ByteSliceToObj

func ByteSliceToObj(store *dstore.Store, oldObj *object.Obj, b []byte, objType object.ObjectType) (*object.Obj, error)

ByteSliceToObj converts a byte slice to an Obj of the specified type and encoding

func ByteSliceToStringObj

func ByteSliceToStringObj(store *dstore.Store, oldObj *object.Obj, b []byte) (*object.Obj, error)

ByteSliceToStringObj converts a byte slice to an Obj with a string value

func DecodeDeqEntry

func DecodeDeqEntry(xb []byte) (x string, entryLen int)

DecodeDeqEntry decode `xb` started from index 0, returns the decoded `x` and the overall length of [enc + data + backlen]. TODO possible optimizations: 1. return the string with the underlying array of `xb` to save memory usage? 2. replace strconv with more efficient/memory-saving implementation

func Encode

func Encode(value interface{}, isSimple bool) []byte

func EncodeDeqEntry

func EncodeDeqEntry(x string) []byte

EncodeDeqEntry encodes `x` into an entry of Deque. An entry will be encoded as [enc + data + backlen].

func EncodeDeqEntryInPlace

func EncodeDeqEntryInPlace(x string, buf []byte)

EncodeDeqEntryInPlace encodes `x` into an entry of Deque in place.

func EncodeDeqInt

func EncodeDeqInt(v int64) []byte

func EncodeDeqIntInPlace

func EncodeDeqIntInPlace(v int64, buf []byte)

func EncodeDeqStr

func EncodeDeqStr(x string) []byte

func EncodeDeqStrInPlace

func EncodeDeqStrInPlace(x string, buf []byte)

func EvalAUTH

func EvalAUTH(args []string, c *comm.Client) []byte

EvalAUTH returns with an encoded "OK" if the user is authenticated If the user is not authenticated, it returns with an encoded error message TODO: Needs to be removed after http and websocket migrated to the multithreading

func GetEncodeDeqEntrySize

func GetEncodeDeqEntrySize(x string) uint64

GetEncodeDeqEntrySize returns the number of bytes the encoded `x` will take.

func GetEncodeDeqIntSize

func GetEncodeDeqIntSize(v int64) uint64

func GetEncodeDeqStrSize

func GetEncodeDeqStrSize(x string) uint64

func IsInt64

func IsInt64(v interface{}) bool

IsInt64 checks if the variable is of type int64.

func IsString

func IsString(v interface{}) bool

IsString checks if the variable is of type string.

Types

type Bloom

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

func CreateOrReplaceBloomFilter

func CreateOrReplaceBloomFilter(key string, opts *BloomOpts, store *dstore.Store) *Bloom

CreateOrReplaceBloomFilter creates a new bloom filter with given `opts` and stores it in the kv store. If the bloom filter already exists, it replaces the existing one. If `opts` is nil, it uses the default options.

func DeserializeBloom

func DeserializeBloom(buf *bytes.Reader) (*Bloom, error)

func GetBloomFilter

func GetBloomFilter(key string, store *dstore.Store) (*Bloom, error)

GetBloomFilter fetches an existing bloom filter from the kv store and returns the datastructure instance of it. The function also returns diceerrors.ErrKeyNotFound if the key does not exist. It also returns diceerrors.ErrWrongTypeOperation if the object is not a bloom filter.

func GetOrCreateBloomFilter

func GetOrCreateBloomFilter(key string, store *dstore.Store, opts *BloomOpts) (*Bloom, error)

GetOrCreateBloomFilter fetches an existing bloom filter from the kv store and returns the datastructure instance of it. If it does not exist, it tries to create one with given `opts` and returns it. Note: It also stores it in the kv store.

func NewBloomFilter

func NewBloomFilter(opts *BloomOpts) *Bloom

newBloomFilter creates and returns a new filter. It is responsible for initializing the underlying bit array.

func (*Bloom) DeepCopy

func (b *Bloom) DeepCopy() *Bloom

DeepCopy creates a deep copy of the Bloom struct

func (*Bloom) Serialize

func (b *Bloom) Serialize(buf *bytes.Buffer) error

type BloomOpts

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

type ByteArray

type ByteArray struct {
	Length int64
	// contains filtered or unexported fields
}

func NewByteArray

func NewByteArray(size int) *ByteArray

NewByteArray initializes a new ByteArray with the given size

func NewByteArrayFromObj

func NewByteArrayFromObj(obj *object.Obj) (*ByteArray, error)

func (*ByteArray) BitCount

func (b *ByteArray) BitCount() int

BitCount counts the number of bits set to 1

func (*ByteArray) DeepCopy

func (b *ByteArray) DeepCopy() *ByteArray

DeepCopy creates a deep copy of the ByteArray

func (*ByteArray) GetBit

func (b *ByteArray) GetBit(pos int) bool

GetBit gets the bit at the given position

func (*ByteArray) IncreaseSize

func (b *ByteArray) IncreaseSize(increaseSizeTo int) *ByteArray

func (*ByteArray) ResizeIfNecessary

func (b *ByteArray) ResizeIfNecessary() *ByteArray

func (*ByteArray) SetBit

func (b *ByteArray) SetBit(pos int, value bool)

SetBit sets the bit at the given position to the specified value

type CountMinSketch

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

CountMinSketch implements a Count-Min Sketch as described by Cormode and Muthukrishnan in their paper: "An Improved Data Stream Summary: The Count-Min Sketch and its Applications" (http://dimacs.rutgers.edu/~graham/pubs/papers/cm-full.pdf).

A Count-Min Sketch (CMS) is a space-efficient, probabilistic data structure for approximating the frequency of events in a data stream. Instead of using large space like a hash map, it trades accuracy for space by allowing a configurable error margin. Similar to Counting Bloom filters, each item is hashed into multiple buckets, and the item's frequency is estimated by taking the minimum count across those buckets.

CMS is particularly useful for tracking event frequencies in large or unbounded data streams where storing all data or maintaining a counter for each event in memory is infeasible. It provides an efficient solution for real-time processing with minimal memory usage.

func DeserializeCMS

func DeserializeCMS(buffer *bytes.Reader) (*CountMinSketch, error)

deserialize reconstructs a CountMinSketch from a byte slice.

func (*CountMinSketch) DeepCopy

func (c *CountMinSketch) DeepCopy() *CountMinSketch

returns a deep copy of the Count Min Sketch

type CountMinSketchOpts

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

type Deque

type Deque struct {
	Length int64
	// contains filtered or unexported fields
}

func DeserializeDeque

func DeserializeDeque(buf *bytes.Reader) (*Deque, error)

func NewDeque

func NewDeque() *Deque

func (*Deque) GetLength

func (q *Deque) GetLength() int64

func (*Deque) LInsert

func (q *Deque) LInsert(pivot, element, beforeAfter string) (int64, error)

Inserts element before/after pivot element.

func (*Deque) LPop

func (q *Deque) LPop() (string, error)

func (*Deque) LPush

func (q *Deque) LPush(x string)

func (*Deque) LRange

func (q *Deque) LRange(start, stop int64) ([]string, error)

Iterates over the Deque and returns the element in order.

func (*Deque) NewIterator

func (q *Deque) NewIterator() *DequeIterator

Creates a new iterator for Deque.

func (*Deque) RPop

func (q *Deque) RPop() (string, error)

func (*Deque) RPush

func (q *Deque) RPush(x string)

func (*Deque) Serialize

func (q *Deque) Serialize(buf *bytes.Buffer) error

type DequeBasic

type DequeBasic struct {
	Length int64
	// contains filtered or unexported fields
}

func NewBasicDeque

func NewBasicDeque() *DequeBasic

func (*DequeBasic) GetLength

func (q *DequeBasic) GetLength() int64

func (*DequeBasic) LInsert

func (q *DequeBasic) LInsert(pivot, element, beforeAfter string) (int64, error)

Inserts element before/after pivot element.

func (*DequeBasic) LPop

func (q *DequeBasic) LPop() (string, error)

LPop pops an element from the left side of the Deque.

func (*DequeBasic) LPush

func (q *DequeBasic) LPush(x string)

LPush pushes `x` into the left side of the Deque.

func (*DequeBasic) LRange

func (q *DequeBasic) LRange(start, stop int64) ([]string, error)

Iterates over the Deque and returns the element in order.

func (*DequeBasic) NewIterator

func (q *DequeBasic) NewIterator() *DequeBasicIterator

func (*DequeBasic) RPop

func (q *DequeBasic) RPop() (string, error)

RPop pops an element from the right side of the Deque.

func (*DequeBasic) RPush

func (q *DequeBasic) RPush(x string)

RPush pushes `x` into the right side of the Deque.

type DequeBasicIterator

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

func (*DequeBasicIterator) HasNext

func (i *DequeBasicIterator) HasNext() bool

func (*DequeBasicIterator) Next

func (i *DequeBasicIterator) Next() (string, error)

type DequeI

type DequeI interface {
	GetLength() int64
	LPush(string)
	RPush(string)
	LPop() (string, error)
	RPop() (string, error)
	LInsert(string, string, string) (int64, error)
	LRange(start, stop int64) ([]string, error)
}

type DequeIterator

type DequeIterator struct {
	CurrentNode       *byteListNode
	ElementsTraversed int64
	BufIndex          int
	// contains filtered or unexported fields
}

func (*DequeIterator) HasNext

func (i *DequeIterator) HasNext() bool

func (*DequeIterator) Next

func (i *DequeIterator) Next() (string, error)

type DiceCmdMeta

type DiceCmdMeta struct {
	Name  string
	Info  string
	Eval  func([]string, *dstore.Store) []byte
	Arity int // number of arguments, it is possible to use -N to say >= N
	KeySpecs
	SubCommands []string // list of sub-commands supported by the command

	// IsMigrated indicates whether a command has been migrated to a new evaluation
	// mechanism. If true, the command uses the newer evaluation logic represented by
	// the NewEval function. This allows backward compatibility for commands that have
	// not yet been migrated, ensuring they continue to use the older Eval function.
	// As part of the transition process, commands can be flagged with IsMigrated to
	// signal that they are using the updated execution path.
	IsMigrated bool

	// NewEval is the newer evaluation function for commands. It follows an updated
	// execution model that returns an EvalResponse struct, offering more structured
	// and detailed results, including metadata such as errors and additional info,
	// instead of just raw bytes. Commands that have been migrated to this new model
	// will utilize this function for evaluation, allowing for better handling of
	// complex command execution scenarios and improved response consistency.
	NewEval func([]string, *dstore.Store) *EvalResponse

	// StoreObjectEval is a specialized evaluation function for commands that operate on an object.
	// It is designed for scenarios where the command and subsequent dependent command requires
	// an object as part of its execution. This function processes the command,
	// evaluates it based on the provided object, and returns an EvalResponse struct
	// Commands that involve object manipulation, is not recommended for general use.
	// Only commands that really requires full object definition to pass across multiple shards
	// should implement this function. e.g. COPY, RENAME etc
	StoreObjectEval func(*cmd.DiceDBCmd, *dstore.Store) *EvalResponse
}

type Eval

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

func NewEval

func NewEval(c *cmd.DiceDBCmd, client *comm.Client, store *dstore.Store, httpOp, websocketOp, preProcessing bool) *Eval

func (*Eval) ExecuteCommand

func (e *Eval) ExecuteCommand() *EvalResponse

func (*Eval) PreProcessCommand

func (e *Eval) PreProcessCommand() *EvalResponse

type EvalResponse

type EvalResponse struct {
	Result interface{} // Result holds the outcome of the Store operation. Currently, it is expected to be of type []byte, but this may change in the future.
	Error  error       // Error holds any error that occurred during the operation. If no error, it will be nil.
}

EvalResponse represents the response of an evaluation operation for a command from store. It contains the sequence ID, the result of the store operation, and any error encountered during the operation.

type HashMap

type HashMap map[string]string

func (HashMap) Get

func (h HashMap) Get(k string) (*string, bool)

func (HashMap) Set

func (h HashMap) Set(k, v string) (*string, bool)

type KeySpecs

type KeySpecs struct {
	BeginIndex int
	Step       int
	LastKey    int
}

type RespType

type RespType int
const (
	NIL                RespType = iota // Represents an empty or null response.
	OK                                 // Represents a successful "OK" response.
	CommandQueued                      // Represents that a command has been queued for execution.
	IntegerZero                        // Represents the integer value zero in RESP format.
	IntegerOne                         // Represents the integer value one in RESP format.
	IntegerNegativeOne                 // Represents the integer value negative one in RESP format.
	IntegerNegativeTwo                 // Represents the integer value negative two in RESP format.
	EmptyArray                         // Represents an empty array in RESP format.
)

type String

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

func NewString

func NewString(value string) *String

func (*String) Serialize

func (s *String) Serialize() []byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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