client.go
client.go - Overview
Defines the Client
struct and related methods for handling client connections, commands, and transaction management within the DiceDB system. It also includes structures for command watch and qwatch responses.
Detailed Documentation
CmdWatchResponse
- Purpose: Represents the response structure for command watch operations.
- Fields:
ClientIdentifierID
(uint32): ID of the client.Result
(interface{}: The result of the command execution.Error
(error): Any error that occurred during command execution.
QwatchResponse
- Purpose: Represents the response structure for qwatch operations.
- Fields:
ClientIdentifierID
(uint32): ID of the client.Result
(interface{}): The result of the operation.Error
(error): Any error that occurred during the operation.
Client
- Purpose: Represents a client connection to the DiceDB.
- Fields:
ReadWriter
(io.ReadWriter): Interface for reading from and writing to the client connection.HTTPQwatchResponseChan
(chan QwatchResponse): Response channel to send back the operation responseFd
(int): File descriptor of the client connection.Cqueue
(cmd.DiceDBCmds): Command queue for the client.IsTxn
(bool): Indicates if the client is currently in a transaction.Session
(*auth.Session): Authentication session for the client.ClientIdentifierID
(uint32): Unique identifier for the client.
(c *Client) Write(b []byte) (int, error)
- Purpose: Writes data to the client's file descriptor.
- Parameters:
b
([]byte): The data to write.
- Returns:
int
: The number of bytes written.error
: Any error that occurred during the write operation.
(c *Client) Read(b []byte) (int, error)
- Purpose: Reads data from the client's file descriptor.
- Parameters:
b
([]byte): The buffer to read into.
- Returns:
int
: The number of bytes read.error
: Any error that occurred during the read operation.
(c *Client) TxnBegin()
- Purpose: Begins a transaction for the client.
- Parameters: None
- Returns: None
(c *Client) TxnDiscard()
- Purpose: Discards the current transaction and clears the command queue.
- Parameters: None
- Returns: None
(c *Client) TxnQueue(diceDBCmd *cmd.DiceDBCmd)
- Purpose: Adds a command to the transaction queue.
- Parameters:
diceDBCmd
(*cmd.DiceDBCmd): The command to add to the queue.
- Returns: None
NewClient(fd int) *Client
- Purpose: Creates a new
Client
instance. - Parameters:
fd
(int): The file descriptor for the client connection.
- Returns:
*Client
: A pointer to the newClient
instance.
NewHTTPQwatchClient(qwatchResponseChan chan QwatchResponse, clientIdentifierID uint32) *Client
- Purpose: Creates a new
Client
instance for HTTP Qwatch operations. - Parameters:
qwatchResponseChan
(chan QwatchResponse): The channel for Qwatch responses.clientIdentifierID
(uint32): Unique identifier for the client.
- Returns:
*Client
: A pointer to the newClient
instance.
Code Examples
Not applicable, as the code is self-explanatory.