Skip to content

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 get started with DiceDB.

Starting DiceDB

dicedb

Once the server starts, you will see output similar to this

2024/08/01 23:44:24 INFO starting an asynchronous TCP server on 0.0.0.0=7379
2024/08/01 23:44:24 INFO ready to accept connections

Starting the DiceDB CLI

To begin, ensure DiceDB is running on your system. Open your terminal or command prompt and type:

Terminal window
dice

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

127.0.0.1:7379>

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

Storing Data: The SET Command

Let’s store our “Hello, World!” message in DiceDB. We’ll use the SET command, which is responsible for storing a string value under a specified key.

Terminal window
127.0.0.1:7379> SET mykey "Hello, World!"
OK

Here’s a breakdown of what happened:

  • SET: This is the DiceDB command to store a value.
  • mykey: This is the key we’re assigning to the value.
  • "Hello, World!": 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
127.0.0.1:7379> GET mykey
"Hello, World!"

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

Closing the Connection

To exit the DiceDB CLI, you can press Ctrl+D or type exit.

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.