Skip to content

Hello, World - Simple

Before we start with Hello, World program for DiceDB, make sure you have

  1. a running instance of DiceDB
  2. 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.0
2025-02-17T07:15:33Z INF running with total_commands=21
2025-02-17T07:15:33Z INF running with engine=ironhawk
2025-02-17T07:15:33Z INF running with port=7379
2025-02-17T07:15:33Z INF running on cores=16
2025-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

Terminal window
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.

Terminal window
localhost:7379> SET k1 v1
OK OK
localhost:7379> GET k1
OK v1

Here’s a breakdown of what happened,

  • SET: This is the DiceDB command to store a value
  • k1: This is the key we’re assigning to the value
  • v1: This is the actual value we want to store. It’s a simple string in this case
  • OK: 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.