Hello, World - Simple
Before we start with Hello, World program for DiceDB, make sure you have
- a running instance of DiceDB
- installed DiceDB CLI
You can follow the steps mentioned in the installation guide to wrap up the installation.
Starting DiceDB
Once the DiceDB server starts, you will see output similar to this
██████╗ ██╗ ██████╗███████╗██████╗ ██████╗ ██╔══██╗██║██╔════╝██╔════╝██╔══██╗██╔══██╗ ██║ ██║██║██║ █████╗ ██║ ██║██████╔╝ ██║ ██║██║██║ ██╔══╝ ██║ ██║██╔══██╗ ██████╔╝██║╚██████╗███████╗██████╔╝██████╔╝ ╚═════╝ ╚═╝ ╚═════╝╚══════╝╚═════╝ ╚═════╝
2025-02-17T07:15:33Z INF starting DiceDB version=0.1.02025-02-17T07:15:33Z INF running with total_commands=212025-02-17T07:15:33Z INF running with engine=ironhawk2025-02-17T07:15:33Z INF running with port=73792025-02-17T07:15:33Z INF running on cores=162025-02-17T07:15:33Z INF running with shards=16
Starting the DiceDB CLI
DiceDB CLI is your portal to all things DiceDB, and once you start you will get a REPL to interact with the database and it looks something like this
localhost:7379>
This indicates that you’re connected to the default DiceDB instance on your local machine on port 7379.
A simple Set-Get Example
DiceDB is a KV store and one of the most basic operations is to store a key and a value and then retrieve it.
To store <k1, v1>
in DiceDB, we use the SET
command and
then retrieve it using the GET
command.
localhost:7379> SET k1 v1OK OKlocalhost:7379> GET k1OK v1
Here’s a breakdown of what happened,
SET
: This is the DiceDB command to store a valuek1
: This is the key we’re assigning to the valuev1
: This is the actual value we want to store. It’s a simple string in this caseOK
: DiceDB’s response indicating successful storage
Note: The first OK
is the status of the command, while the second OK
is the output of the command.
Bottom Line
This is just the tip of the iceberg when it comes to DiceDB. We’ve covered the basics of connecting to a DiceDB instance, storing a simple string, and retrieving it. The true power of DiceDB lies in its ability to intuitively build reactive applications like chatrooms, handle complex data structures and perform operations efficiently. But all of that after we do our first tutorial for reactivity and query subscriptions.