Getting up Your Real-Time Key-Value Store with RedixDB

By Dassi Orleando, Alibaba Cloud Community Blog author.

RedixDB is an open-source and real-time key-value store that uses the same protocol as Redis along with several other additional features, including a fast non-relational database, which also uses the same RESP protocol and is capable of storing several terabytes of data. RedixDB integrates several real-time features through which it can serve as a document store, making it a multi-model database.

In this article, we’ll cover how you can install and set up RedixDB on an Alibaba Cloud Elastic Compute Service (ECS) instance. Next, in this article, we will also cover some basic commands and how you can use and take advantage of some of the major features of RedixDB.

Installing and Setting up Redix

Next, now it comes to the fun part, installing Redix, which is relatively straightforward. We can quickly install it from binary. To get the corresponding binary to our operating system, we will need to access the releases page on GitHub and select the appropriate one depending on our platform.

At the time of writing this article the latest version is 1.8, which was released on the 02 January 2019, which we can pick up here by using the following command to get it on our remote machine:

wget https://github.com/alash3al/redix/releases/download/v1.8/redix_linux_amd64.zip

Now we need to unzip the compressed file using the unzip package as follows: First, the command unzip redix_linux_amd64.zip is used to unzip it into the current directory. For a different destination we'll need to specify the –d option with a value, that is, the destination folder, either in a relative or absolute way. Next, we will have a redix_linux_amd64 executable used to run Redix. After you have that, you'll want to run ./redix_linux_amd64 –h to be sure all is well as it'll show the help, you'll get such a response:

Usage of ./redix_linux_amd64:
-engine string
the storage engine to be used (default "badger")
-http-addr string
the address of the http server (default ":7090")
-resp-addr string
the address of resp server (default ":6380")
-storage string
the storage directory (default "./redix-data")
-verbose
verbose or not
-workers int
the default workers number (default 1)

Let’s note that there is also a Docker image for quicker installation with the following command:

docker run -P -v /path/to/redix-data:/root/redix-data alash3al/redix

Running Redix

{"message":"welcome to redix real-time db :)","success":true}

Once you see this, it means that everything is working as expected.

Setting Redix’s Configurations

  • engine: This defines the storage engine to be used. The default setting is badger.
  • http-addr: This specifies the address of the http server. The default is the current machine on port 7090.
  • resp-addr: This denotes the address of the resp server. Th default is the current machine on the port 6380.
  • storage: This serves as the storage directory. The default is ./redix-data.
  • workers: This states the number of workers. The default is 1.
  • verbose: This determines whether it'll be verbose or not.

The Features of Redix

  • Core data structure manipulations extensible storage engine.
  • Publish or subscribe using web hook and web socket.
  • Working with any available redis client including redis-cli.
  • Helpers commands for time, encoding and random: Time, Encode <hex|md5|sha1|sha256|sha512> <payload>, RANDINT, RANDSTR, RATELIMIT

The DB Engines of Redix

They may be similar in terms of key-value way to store stuff, including the commands to interact with our data and the core protocol used for storage. However, Redix in addition also allows to use different kind of engine which is a great feature leading the store to be multi-model further.

Redix also supports many engines within the most popular and used are badger (inspired by Facebook RocksDB) and bolt (inspired by LMDB), here are some others:

  • level based on leveldb
  • null
  • sqlite

Example Commands

  • redis-cli -p 6380 set key1 "value 1": defines "value 1" for the key key1 i.e key1 = "value 1"
  • redis-cli -p 6380 set key2 "value 2" 10000: here key2 has value2 as value which will expire in 10 seconds.
  • redis-cli -p 6380 get key1: to load and print key1 value (value 1)
  • redis-cli -p 6380 hset key3 x y: means key3[x] = y
  • redis-cli -p 6380 hget key3 x: load/print key3's x value as it's a hash map
  • redis-cli -p 6380 encode sha512 message: outputs the sha512 encoded representation of text "message"

Strings

  • MSET <key1> <value1> [<key2> <value2> ...]
  • GET <key> [<default value>]
  • MGET <key1> [<key2> ...]
  • DEL <key1> [<key2> ...]
  • EXISTS <key>
  • INCR <key> [<by>]
  • TTL <key> returns -1 if key will never expire, -2 if it doesn't exist (expired), otherwise will returns the seconds remain before the key will expire.
  • KEYS [<regexp-pattern>]

HASHES

  • HMSET <HASHMAP> <key1> <value1> [<key2> <value2> ...]
  • HGET <HASHMAP> <KEY>
  • HDEL <HASHMAP> [<key1> <key2> ...] (deletes the map itself or keys in the map)
  • HGETALL <HASHMAP>
  • HMSET <HASHMAP> <key1> <val1> [<key2> <val2> ...]
  • HEXISTS <HASHMAP> [<key>].
  • HINCR <HASHMAP> <key> [<by>]
  • HTTL <HASHMAP> <key>, the same as TTL but for HASHMAP`
  • HKEYS <HASHMAP>
  • HLEN <HASHMAP>

SET

  • SMEMBERS <LIST> [<offset> <size>] (alias of LRANGE)
  • SSCAN <LIST>
  • SCARD <LIST> (aliad of LCOUNT)
  • SREM <LIST> [<val1> <val2> <val3> ...] (alias of LREM)

SET

  • UUIDV4, generates a uuid-v4 string, i.e 44e38a44-95eb-4221-8118-b8594a711570.
  • UNIQID, generates a unique string.
  • RANDSTR [<size>, default size is 10], generates a random string using the specified length.
  • RANDINT <min> <max>, generates a random string between the specified <min> and <max>.
  • TIME, returns the current time in utc, seconds and nanoseconds
  • DBSIZE, returns the database size in bytes.
  • GC, runs the Garbage Collector.
  • ECHO [<arg1> <arg2> ...]
  • INFO

You can access more details of supported commands illustrated into the official documentation.

Conclusion

Original Source

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.