eval.go
eval.go - Overview
This file contains the evaluation logic for various DiceDB commands, including authentication (AUTH
), server information (HELLO
), and utility functions (SLEEP
). It also defines the EvalResponse
struct for encapsulating command results and errors.
Detailed Documentation
Variables
TxnCommands map[string]bool
: A map indicating which commands are transaction-related (e.g.,EXEC
,DISCARD
).serverID string
: Stores the server's ID in the format "host:port".diceCommandsCount int
: Stores the number of DiceDB commands.
Constants
Uninitialized exDurationState
: Represents an uninitialized expiration duration state.Initialized exDurationState
: Represents an initialized expiration duration state.IncrBy jsonOperation
: String constant for "INCRBY" operation.MultBy jsonOperation
: String constant for "MULTBY" operation.defaultRootPath string
: String constant for default JSON root path "$".maxExDuration int64
: Max expiration duration.CountConst string
: String constant for "COUNT".
Struct EvalResponse
- Purpose: Represents the response from evaluating a command.
- Fields:
Result interface{}
: The result of the command evaluation.Error error
: Any error that occurred during evaluation.
- Methods:
makeEvalResult(result interface{}) *EvalResponse
: Creates a newEvalResponse
with the given result and a nil error.- Parameters:
result interface{}
: The result of the store operation.
- Returns: A new
EvalResponse
with the given result and nil error.
- Parameters:
makeEvalError(err error) *EvalResponse
: Creates a newEvalResponse
with the given error and a nil result.- Parameters:
err error
: The error that occurred during the store operation.
- Returns: A new
EvalResponse
with the given error and nil result.
- Parameters:
Functions
EvalAUTH(args []string, c *comm.Client) []byte
: Evaluates theAUTH
command.- Purpose: Authenticates a user against the configured username and password.
- Parameters:
args []string
: The arguments provided to theAUTH
command (password, or username and password).c *comm.Client
: The client connection.
- Returns: An encoded "OK" response on success, or an encoded error message on failure.
evalHELLO(args []string, store *dstore.Store) []byte
: Evaluates theHELLO
command.- Purpose: Returns server information.
- Parameters:
args []string
: The arguments provided to theHELLO
command.store *dstore.Store
: The data store.
- Returns: An encoded response containing server details like protocol version, server ID, mode, role, and modules.
evalSLEEP(args []string, store *dstore.Store) []byte
: Evaluates theSLEEP
command.- Purpose: Makes the server sleep for a specified duration.
- Parameters:
args []string
: The arguments provided to theSLEEP
command (sleep duration in seconds).store *dstore.Store
: The data store.
- Returns:
RespOK
after sleeping, or an error if the duration is invalid.