Skip to content

Simple Hello, World!

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

██████╗ ██╗ ██████╗███████╗██████╗ ██████╗
██╔══██╗██║██╔════╝██╔════╝██╔══██╗██╔══██╗
██║ ██║██║██║ █████╗ ██║ ██║██████╔╝
██║ ██║██║██║ ██╔══╝ ██║ ██║██╔══██╗
██████╔╝██║╚██████╗███████╗██████╔╝██████╔╝
╚═════╝ ╚═╝ ╚═════╝╚══════╝╚═════╝ ╚═════╝
2024-10-24T06:25:32Z INF starting DiceDB version=0.0.5
2024-10-24T06:25:32Z INF running with port=7379
2024-10-24T06:25:32Z INF running with enable-watch=true
2024-10-24T06:25:32Z INF running with mode=multi-threaded num-shards=32
2024-10-24T06:25:32Z INF ready to accept and serve requests on port=7379

Starting the DiceDB CLI

Open your terminal or command prompt and fire the following command

Terminal window
dicedb-cli

This command launches the DiceDB CLI REPL, presenting you with a prompt similar to this

Connected to DiceDB. Type 'exit' or press Ctrl+D to exit.
dicedb>

This indicates that you’re connected to the default DiceDB instance on your local machine on port 7379.

Storing Data: The SET Command

Let’s store <k1, v1> in DiceDB. We’ll use the SET command, which is responsible for storing a string value under a specified key.

Terminal window
dicedb> SET k1 v1
OK

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.

Retrieving Data: The GET Command

Now, let’s fetch the stored value using the GET command.

Terminal window
dicedb> GET k1
v1

The GET command retrieves the value associated with the specified key. In this case, we retrieved the “v1” message we stored earlier.

Conclusion

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 realtime reactive applications like leaderboards, handle complex data structures and perform operations efficiently.