Hello, World
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 get started with DiceDB.
Starting DiceDB
Once the server starts, you will see output similar to this
Starting the DiceDB CLI
To begin, ensure DiceDB is running on your system. Open your terminal or command prompt and type:
This command launches the DiceDB CLI, presenting you with a prompt similar to this:
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.
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.
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.