DiceDB is an in-memory real-time database with SQL-based reactivity. It is hyper-optimized for building and scaling truly real-time applications on modern hardware while being a drop-in replacement for Redis.
Note: DiceDB is still in development and it supports a subset of Redis commands. So, please do not use it in production. But, feel free to go through the open issues and contribute to help us speed up the development.
Although DiceDB is a drop-in replacement of Redis, which means almost no learning curve and switching does not require any code change, it still differs in two key aspects and they are
- DiceDB is multi-threaded and follows shared-nothing architecture.
- DiceDB supports a new command called
QWATCH
that lets clients listen to a SQL query and get notified in real-time whenever something changes.
With this, you can build truly real-time applications like Leaderboard with simple SQL query.
The easiest way to get started with DiceDB is using Docker by running the following command.
$ docker run dicedb/dicedb
The above command will start the DiceDB server running locally on the port 7379
and you can connect
to it using DiceDB CLI and SDKs, or even Redis CLIs and SDKs.
Note: Given it is a drop-in replacement of Redis, you can also use any Redis CLI and SDK to connect to DiceDB.
To run DiceDB for local development or running from source, you will need
- Golang
- Any of the below supported platform environment:
- Linux based environment
- OSX (Darwin) based environment
- WSL under Windows
$ git clone https://github.com/dicedb/dice
$ cd dice
$ go run main.go
- Install GoLangCI
$ sudo su
$ curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /bin v1.60.1
DiceDB provides a hot-reloading development environment, which allows you to instantly view your code changes in a live server. This functionality is supported by Air
To Install Air on your system you have following options.
- If you're on go 1.22+
go install github.com/air-verse/air@latest
- Install the Air binary
# binary will be installed at $(go env GOPATH)/bin/air
curl -sSfL https://raw.githubusercontent.com/air-verse/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
Once air
is installed you can verify the installation using the command air -v
To run the live DiceDB server for local development:
$ git clone https://github.com/dicedb/dice
$ cd dice
$ air
By default, DiceDB will look for the configuration file at /etc/dice/config.toml
. (Linux, Darwin, and WSL)
$ # set up configuration file # (optional but recommended)
$ sudo mkdir -p /etc/dice
$ sudo chown root:$USER /etc/dice
$ sudo chmod 775 /etc/dice # or 777 if you are the only user
$ git clone https://github.com/DiceDB/dice.git
$ cd dice
$ go run main.go -init-config
If you're using Windows, it is recommended to use Windows Subsystem for Linux (WSL) or WSL 2 to run the above commands seamlessly in a Linux-like environment.
Alternatively, you can:
Create a directory at C:\ProgramData\dice
and run the following command to generate the configuration file:
go run main.go -init-config
For a smoother experience, we highly recommend using WSL.
If you'd like to use a different location, you can specify a custom configuration file path with the -c flag
:
go run main.go -c /path/to/config.toml
If you'd like to output the configuration file to a specific location, you can specify a custom output path with the -o flag
:
go run main.go -o /path/of/output/dir
The best way to connect to DiceDB is using DiceDB CLI and you can install it by running the following command.
$ pip install dicedb-cli
Because DiceDB speaks Redis dialect, you can connect to it with any Redis Client and SDK also. But if you are planning to use the
QWATCH
feature then you need to use the DiceDB CLI.
Unit tests and integration tests are essential for ensuring correctness and in the case of DiceDB, both types of tests are available to validate its functionality.
For unit testing, you can execute individual unit tests by specifying the name of the test function using the TEST_FUNC
environment variable and running the make unittest-one
command. Alternatively, running make unittest
will execute all unit tests.
$ TEST_FUNC=<name of the test function> make unittest-one
$ TEST_FUNC=TestByteList make unittest-one
$ make unittest
Integration tests, on the other hand, involve starting up the DiceDB server and running a series of commands to verify the expected end state and output. To execute a single integration test, you can set the TEST_FUNC
environment variable to the name of the test function and run make test-one
. Running make test
will execute all integration tests.
$ TEST_FUNC=<name of the test function> make test-one
$ TEST_FUNC=TestSet make test-one
$ make test
Work to add more tests in DiceDB is in progress and we will soon port the test Redis suite to this codebase to ensure full compatibility.
$ go test -test.bench <pattern>
$ go test -test.bench BenchmarkListRedis -benchmem
To get started with building and contributing to DiceDB, please refer to the issues created in this repository.
DiceDB started as a re-implementation of Redis in Golang and the idea was to - build a DB from scratch and understand the micro-nuances that come with its implementation. The database does not aim to replace Redis, instead, it will fit in and optimize itself for multi-core computations running on a single-threaded event loop.
The Code Contribution Guidelines are published at CONTRIBUTING.md; please read them before you start making any changes. This would allow us to have a consistent standard of coding practices and developer experience.
Contributors can join the Discord Server for quick collaboration.
$ sudo netstat -atlpn | grep :7379
$ sudo kill -9 <process_id>