### DiceDB Set and Get Example Source: https://github.com/dicedb/dice/blob/master/docs/src/content/docs/get-started/hello-world.mdx Demonstrates the basic DiceDB operations for storing a key-value pair using the SET command and retrieving it with the GET command. This is a fundamental example for interacting with the key-value store. ```bash localhost:7379> SET k1 v1 OK localhost:7379> GET k1 OK "v1" ``` -------------------------------- ### Install and Run Development Server Source: https://github.com/dicedb/dice/blob/master/CONTRIBUTING/docs.md Commands to install dependencies and start the local development server for the DiceDB documentation. This setup uses npm and provides hot reloading. ```bash cd docs npm install npm run dev ``` -------------------------------- ### Hello, World Examples for Protocols Source: https://github.com/dicedb/dice/blob/master/docs/src/content/updates/2024-10-24.md Added 'Hello, World!' examples for both Simple and Reactive protocols, demonstrating basic usage and setup for each. ```APIDOC Simple Protocol Example: - Connect to the server. - Send a PING command. - Receive a PONG response. Reactive Protocol Example: - Establish a reactive connection. - Subscribe to a channel. - Receive messages asynchronously. ``` -------------------------------- ### Start DiceDB Mock Server Source: https://github.com/dicedb/dice/blob/master/examples/leaderboard-go/README.md Initiates the DiceDB server in mock mode. This is the first step in setting up the leaderboard simulation. ```sh $ go run main.go mock ``` -------------------------------- ### Install GolangCI-Lint Source: https://github.com/dicedb/dice/blob/master/CONTRIBUTING/development-setup.md Installs the `golangci-lint` tool using a script provided by the official repository. This linter is used for static analysis of Go code. ```bash sudo su sudo curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/local/bin v1.64.6 ``` -------------------------------- ### Run DiceDB Go Example Source: https://github.com/dicedb/dice/blob/master/examples/hello-world-go/README.md Command to execute the Go program that interacts with DiceDB. ```bash go run main.go ``` -------------------------------- ### Run DiceDB Client Sessions Source: https://github.com/dicedb/dice/blob/master/examples/leaderboard-go/README.md Starts additional DiceDB client sessions to interact with the running server for the leaderboard simulation. Requires 3 separate terminal sessions. ```sh $ go run main.go ``` -------------------------------- ### Install DiceDB Go SDK Source: https://github.com/dicedb/dice/blob/master/docs/src/content/docs/sdk/go.mdx Installs the DiceDB Go SDK using the go get command. Ensure you are using the specified version for compatibility. ```bash go get github.com/dicedb/dicedb-go@v1.0.9 ``` -------------------------------- ### Install and Run DiceDB Source: https://github.com/dicedb/dice/blob/master/docs/src/content/docs/tutorials/url-shortener.md Starts a DiceDB server using Docker, exposing it on port 7379. This is a prerequisite for the URL shortener application. ```bash docker run -d -p 7379:7379 dicedb/dicedb ``` -------------------------------- ### DiceDB SET Command Example (Bash) Source: https://github.com/dicedb/dice/blob/master/docs/sample_command_docs.md Examples demonstrating the usage of the SET command in DiceDB via bash. ```bash 127.0.0.1:7379> SET foo bar OK 127.0.0.1:7379> SET foo bar EX 10 OK ``` -------------------------------- ### Start the Go Application Source: https://github.com/dicedb/dice/blob/master/docs/src/content/docs/tutorials/url-shortener.md Command to run the main Go application file. This starts the server on the default port 8080. ```bash go run main.go ``` -------------------------------- ### Install DiceDB CLI using cURL Source: https://github.com/dicedb/dice/blob/master/README.md Installs the DiceDB CLI by downloading and executing an installation script. This is the recommended way to connect to DiceDB. If your OS is unsupported, refer to the CLI repository for manual installation instructions. ```shell sudo su curl -sL https://raw.githubusercontent.com/DiceDB/dicedb-cli/refs/heads/master/install.sh | sh ``` -------------------------------- ### Execute Single Unit Test Source: https://github.com/dicedb/dice/blob/master/CONTRIBUTING/development-setup.md Runs a specific unit test by setting the `TEST_FUNC` environment variable before executing `make unittest-one`. An example is provided for `TestByteList`. ```bash TEST_FUNC= make unittest-one TEST_FUNC=TestByteList make unittest-one ``` -------------------------------- ### WebSocket Documentation CLI Example Source: https://github.com/dicedb/dice/blob/master/docs/src/content/updates/2024-10-24.md Added a Command Line Interface (CLI) example to the WebSocket documentation to illustrate how to interact with the server using the command line. ```CLI # Example CLI command for WebSocket connection ./dicedb-cli --protocol websocket ws://localhost:6379 ``` -------------------------------- ### TTL Command Examples Source: https://github.com/dicedb/dice/blob/master/docs/src/content/docs/commands/TTL.md Examples demonstrating the usage of the TTL command with different scenarios, including keys with and without expiration, and non-existent keys. ```redis-cli localhost:7379> SET k 43 OK localhost:7379> TTL k OK -1 localhost:7379> SET k 43 EX 10 OK localhost:7379> TTL k OK 8 localhost:7379> TTL kn OK -2 ``` -------------------------------- ### Start DiceDB Server Source: https://github.com/dicedb/dice/blob/master/docs/src/content/docs/tutorials/realtime-leaderboard.mdx Starts the DiceDB server with watch mode enabled. This is crucial for enabling real-time updates. ```bash docker run -p 7379:7379 dicedb/dicedb --enable-watch ``` -------------------------------- ### Q.WATCH Basic Usage Example Source: https://github.com/dicedb/dice/blob/master/docs/src/content/docs/QWATCH.md Demonstrates a practical example of using the Q.WATCH command to monitor a real-time leaderboard, including filtering by key pattern and value, and ordering results. ```bash 127.0.0.1:7379> Q.WATCH "SELECT $key, $value WHERE $key like 'match:100:*' AND $value > 10 ORDER BY $value DESC LIMIT 3" q.watch from SELECT $key, $value WHERE $key like 'match:100:*' AND $value > 10 ORDER BY $value asc: [] ``` -------------------------------- ### DiceDB Commands: SET and GET Source: https://github.com/dicedb/dice/blob/master/docs/src/content/docs/tutorials/url-shortener.md Documentation for essential DiceDB commands used in the URL shortener. Explains the syntax, parameters, and usage of `SET` for storing data and `GET` for retrieving data. ```apidoc SET key value [expiration] - Stores a key-value pair in DiceDB. - Parameters: - key: Unique identifier (e.g., short URL code) - value: Data to store (e.g., serialized JSON) - expiration: Optional; time-to-live in seconds (use 0 for no expiration) GET key - Retrieves the value associated with a key. - Parameters: - key: Identifier for the data to retrieve ``` -------------------------------- ### DiceDB Go SDK Basic Operations Source: https://github.com/dicedb/dice/blob/master/examples/hello-world-go/README.md Demonstrates setting a key 'k1' to 'v1' and then retrieving the value for 'k1' using the DiceDB Go SDK. ```go package main import ( "fmt" "github.com/DiceDB/dice_go_sdk" ) func main() { // Initialize DiceDB client db, err := dice_go_sdk.NewClient("localhost:6379") // Replace with your DiceDB host and port if err != nil { fmt.Printf("Error connecting to DiceDB: %v\n", err) return } // Set a key-value pair err = db.Set("k1", "v1") if err != nil { fmt.Printf("Error setting key: %v\n", err) return } // Get the value for a key value, err := db.Get("k1") if err != nil { fmt.Printf("Error getting key: %v\n", err) return } fmt.Printf("Value for k1: %s\n", value) } ``` -------------------------------- ### playground-web Updates Source: https://github.com/dicedb/dice/blob/master/docs/src/content/updates/2024-10-17.md This section outlines updates for the playground-web repository, including support for the JSON.SET command, unit tests, Docker Compose context fixes, NextJS setup with Electron for the DiceDB Console, and styling adjustments for the get started button. ```APIDOC APIDOC: JSON.SET Command - Adding support. Unit Tests - Added unit tests for playground-web repository. Docker Compose - Fix docker compose contexts to ensure docker compose runs. DiceDB Console - Setup NextJS with Electron. Styling - Fixed the styling of get started button. External Links - Add external links to footer items. ``` -------------------------------- ### Initialize Go Project and Install Packages Source: https://github.com/dicedb/dice/blob/master/docs/src/content/docs/tutorials/url-shortener.md Sets up a new Go project directory, initializes a Go module, and installs the necessary packages: DiceDB Go SDK, Gin web framework, and Google's UUID library. ```bash mkdir url-shortener cd url-shortener go mod init url-shortener go get github.com/dicedb/dicedb-go@v1.0.3 go get github.com/gin-gonic/gin go get github.com/google/uuid ``` -------------------------------- ### DiceDB JSON.ARRLEN Root Path Example Source: https://github.com/dicedb/dice/blob/master/docs/src/_skipped_commands/JSON.ARRLEN.md Example demonstrating how to get the length of a JSON array stored at the root path of a key ('user:1002'). ```bash 127.0.0.1:7379> JSON.ARRLEN user:1002 (integer) 3 ``` -------------------------------- ### DiceDB JSON.ARRLEN Basic Usage Example Source: https://github.com/dicedb/dice/blob/master/docs/src/_skipped_commands/JSON.ARRLEN.md Example showing how to get the length of a specific array ('emails') within a JSON document stored under the key 'user:1001'. ```bash 127.0.0.1:7379> JSON.ARRLEN user:1001 $.emails (integer) 2 ``` -------------------------------- ### Build DiceDB Server from Source Source: https://github.com/dicedb/dice/blob/master/CONTRIBUTING/development-setup.md Clones the DiceDB repository, navigates into the directory, and builds the DiceDB server binary using `make build`. This process requires Golang and a supported platform environment. ```sh git clone https://github.com/dicedb/dice cd dice make build ``` -------------------------------- ### DiceDB JSON.ARRINDEX Usage Example with Start Index Source: https://github.com/dicedb/dice/blob/master/docs/src/_skipped_commands/JSON.ARRINDEX.md Demonstrates using the JSON.ARRINDEX command to find the index of a value in a JSON array, starting the search from a specified index. ```bash 127.0.0.1:7379> JSON.SET b $ '{"name": "Alice", "mobile": [1902, 1903, 1904]}' "OK" 127.0.0.1:7379> JSON.ARRINDEX a $.mobile 1902 0 1) (integer) 0 127.0.0.1:7379> JSON.ARRINDEX a $.mobile 1902 1 1) (integer) -1 ``` -------------------------------- ### Run All Unit Tests Source: https://github.com/dicedb/dice/blob/master/CONTRIBUTING/development-setup.md Executes all available unit tests for the DiceDB project by running the `make unittest` command. ```bash make unittest ``` -------------------------------- ### DiceDB JSON.ARRLEN Non-Existent Path Example Source: https://github.com/dicedb/dice/blob/master/docs/src/_skipped_commands/JSON.ARRLEN.md Illustrates the error returned when attempting to get the length of an array at a path that does not exist ('$.emails' in 'user:1003'). ```bash 127.0.0.1:7379> JSON.ARRLEN user:1003 $.emails (error) ERROR Path '$.emails' does not exist ``` -------------------------------- ### Run DiceDB Server with Go Source: https://github.com/dicedb/dice/blob/master/CONTRIBUTING/development-setup.md Executes the DiceDB server directly using the `go run main.go` command. This is an alternative to building a binary and is useful for development. ```go go run main.go ``` -------------------------------- ### DiceDB Server Startup Source: https://github.com/dicedb/dice/blob/master/docs/src/data/benchmarks.mdx This snippet shows the typical startup output of the DiceDB server, including version, engine, port, and core/shard configurations. ```bash $ ./dicedb ██████╗ ██╗ ██████╗███████╗██████╗ ██████╗ ██╔══██╗██║██╔════╝██╔════╝██╔══██╗██╔══██╗ ██║ ██║██║██║ █████╗ ██║ ██║██████╔╝ ██║ ██║██║██║ ██╔══╝ ██║ ██║██╔══██╗ ██████╔╝██║╚██████╗███████╗██████╔╝██████╔╝ ╚═════╝ ╚═╝ ╚═════╝╚══════╝╚═════╝ ╚═════╝ 2025-03-09T16:46:03+05:30 INF starting DiceDB version=0.1.0 2025-03-09T16:46:03+05:30 INF running with total_commands=21 2025-03-09T16:46:03+05:30 INF running with engine=ironhawk 2025-03-09T16:46:03+05:30 INF running with port=7379 2025-03-09T16:46:03+05:30 INF running on cores=4 2025-03-09T16:46:03+05:30 INF running with shards=4 ``` -------------------------------- ### DiceDB HTTP API Reference Source: https://github.com/dicedb/dice/blob/master/docs/src/content/docs/protocols/http.mdx This section details the DiceDB HTTP API, including the base URL structure, required headers, and the general request body format. It also provides examples for common commands like SET, GET, HSET, and HGET, showcasing both the HTTP request and cURL equivalents. ```APIDOC DiceDB HTTP API Base URL: http://your-server-address:port/ General Request Structure: - HTTP Method: POST - Path: DiceDB command name (e.g., /SET, /GET, /HSET, /HGET) - Headers: - Content-Type: application/json - Body: JSON object containing command arguments Query Parameters: - key_prefix: Used for JSON.INGEST command to specify a key prefix. Supported Commands: All DiceDB commands are supported via HTTP. Refer to the comprehensive command reference for details. Examples: 1. Setting a Key-Value Pair: Request: POST /SET HTTP/1.1 Host: your-server-address Content-Type: application/json { "key": "mykey", "value": "Hello, World!" } cURL: curl --location 'http://your-server-address:PORT/SET' \ --header 'Content-Type: application/json' \ --data '{ "key": "mykey", "value": "Hello, World!" }' Response: { "status": "success", "data": "OK" } 2. Getting a Value: Request: POST /GET HTTP/1.1 Host: your-server-address Content-Type: application/json { "key": "mykey" } cURL: curl --location 'http://your-server-address:PORT/GET' \ --header 'Content-Type: application/json' \ --data '{ "key": "mykey" }' Response: { "status": "success", "data": "Hello, World!" } 3. Setting a field in Hash: Request: POST /HSET HTTP/1.1 Host: your-server-address Content-Type: application/json { "key": "test", "field": "test", "value": "test" } cURL: curl --location 'http://your-server-address:PORT/HSET' \ --header 'Content-Type: application/json' \ --data '{ "key": "test", "field": "test", "value": "test" }' Response: { "status": "success", "data": 1 } 4. Getting a field in a HashSet: Request: POST /HGET HTTP/1.1 Host: your-server-address Content-Type: application/json { "key": "test", "field": "test" } cURL: curl --location 'http://your-server-address:PORT/HGET' \ --header 'Content-Type: application/json' \ --data '{ "key": "test", "field": "test" }' Response: { "status": "success", "data": "test" } ``` -------------------------------- ### Run All Integration Tests Source: https://github.com/dicedb/dice/blob/master/CONTRIBUTING/development-setup.md Executes all integration tests for the DiceDB project by running the `make test` command. This verifies the DiceDB server's behavior with a series of commands. ```bash make test ``` -------------------------------- ### GET Command Source: https://github.com/dicedb/dice/blob/master/docs/src/content/docs/commands/GET.md Retrieves the value associated with a key in DiceDB. If the key does not exist, it returns an empty string. The command is demonstrated with SET and GET operations. ```APIDOC GET key - Returns the value as a string for the key in args. - Returns an empty string if the key does not exist. Parameters: key: The key whose value is to be retrieved. Examples: localhost:7379> SET k1 v1 OK localhost:7379> GET k1 OK "v1" localhost:7379> GET k2 OK "" ``` -------------------------------- ### Clone and Run Application Source: https://github.com/dicedb/dice/blob/master/docs/src/content/docs/tutorials/realtime-leaderboard.mdx Clones the leaderboard application repository and runs the Go application server. ```bash git clone https://github.com/arpitbbhayani/leaderboard-go-dicedb.git cd leaderboard-go-dicedb go run main.go ``` -------------------------------- ### Build DiceDB CLI from Source Source: https://github.com/dicedb/dice/blob/master/CONTRIBUTING/development-setup.md Clones the dicedb-cli repository, changes directory, and builds the CLI binary using `make build`. The resulting binary connects to a running DiceDB server. ```sh git clone https://github.com/DiceDB/dicedb-cli cd dicedb-cli make build ```