WebSockets
Introduction
DiceDB supports WebSocket for connecting to the database, allowing for real-time, bidirectional communication between the client and the server. This can be particularly useful for applications that require low-latency, high-frequency updates.
Connecting to the WebSocket Server
To connect to the WebSocket server, use the following URL:
Replace your-server-address
and port
with the appropriate values for your server.
Message Format
WebSocket messages should be sent as plain text, following this format:
- The command should be in uppercase.
- Arguments should be separated by spaces.
- For commands that require JSON data, include it as the last argument.
This is very similar to what you’d type in the DiceDB CLI.
Supported Commands
All DiceDB commands are supported over the WebSocket protocol. If some commands are not supported, they will be flagged as such in the command documentation.
For more information on specific commands and their usage, please refer to the command documentation, keeping in mind the WebSocket-specific formatting requirements outlined in this guide.
Special Commands
ABORT
: This command will shut down the WebSocket server.
Responses
Responses are sent back through the WebSocket connection as JSON-encoded data. The structure of the response will depend on the command executed.
Example Usage
Here’s a simple example of how to interact with the WebSocket server: