Getting Started with Redis Enterprise CRDBs (conflict-free replicated databases)
In this guide, we'll set up a CRDB (conflict-free replicated database) spanning across two Redis Enterprise Software clusters for test and development environments. Here are the steps:
- Step 1: Run two RS Docker containers
- Step 2: Setup each container as a cluster
- Step 3: Create a new Redis Enterprise CRDB
- Step 4: Test connectivity to the CRDB
To run a CRDB on installations from the RS download package, setup two RS installations and continue from Step 2.
Note: This getting started guide is for development or demonstration environments. To setup CRDB in a production environment, use the instuctions for creating a CRDB.
Step 1: Run Two Containers
To spin up two RS containers, run these commands:
$ docker run -d --cap-add sys_resource -h rp1_node1 --name rp1_node1 -p 8443:8443 -p 9443:9443 -p 12000:12000 redislabs/redis
$ docker run -d --cap-add sys_resource -h rp2_node1 --name rp2_node1 -p 8445:8443 -p 9445:9443 -p 12002:12000 redislabs/redis
The -p options map the web UI port (8443), REST API port (9443), and database access port differently for each container to make sure that all containers can be accessed from the host OS that is running the containers.
Step 2: Setup Two Clusters
For cluster 1, direct your browser to https://localhost:8443 on the host machine to see the Redis Enterprise Software web console. Simply click the Setup button on the page to get started.
Note: Depending on your browser, you may see a certificate error. Continue to the website.
On the node configuration page, select your default settings and provide a cluster FQDN, for example
cluster1.local. Then click Next button.
If you don't have a license key, click the Next button to try the trial version of the product.
On the next screen, set up a Cluster Administrator account using an email for the login and a password.
Click OK to confirm that you are aware of the replacement of the HTTPS SSL/TLS certificate on the node, and proceed through the browser warning.
Repeat the same operations for cluster 2 with these differences:
- In your web browser, go to https://localhost:8445 to set up the cluster 2.
- For the Cluster name (FQDN), enter a different name, such as
Now we have two Redis Enterprise Software clusters with FQDNs cluster1.local and cluster2.local.
Step 3: Create a Redis CRDB
After you login to cluster1.local, select the Redis database and deployment type Geo-Distributed. Then click Next.
In create database, click the show advanced option and:
- For the database name, enter:
- For the endpoint port number, enter:
- In the participating clusters list, add the address and admin credentials for:
http://cluster1.local:8080- the cluster you are currently connected to
http://cluster2.local:8080- the other cluster
In the Database clustering option, either:
- Make sure the Database clustering is enabled and select the number of shards that you want to have in the database. When database clustering is enabled, databases are subject to limitations on Multi-key commands. You can increase the number of shards in the database at any time.
- Clear the Database clustering option to use only one shard and so
that the Multi-key commands
limitations do not apply.
Note: You cannot enable or disable database clustering after the CRDB is created.
- For the database name, enter:
Click Activate to create your CRDB.
Note: If you cannot activate the database because of a memory limitation, make sure that Docker has enough memory allocated in the Advanced section of Docker Settings.
Make sure that each cluster has a CRDB member database with the name
In a real-world deployment, cluster 1 and cluster 2 would most likely be in separate data centers in different regions. However, for local testing we created the scale-minimized deployment using two local clusters running on the same host.
Step 4: Test the Connection to your Member Redis CRDBs
With the Redis database created, you are ready to connect to your database to store data. You can use one of the following ways to test connectivity to your database:
- Connect with redis-cli, the built-in command-line tool
- Connect with a Hello World application written in Python
Remember we have two member CRDBs that are available for connections and concurrent reads and writes. The member CRDBs are using bi-directional replication to for the global CRDB.
Connecting Using redis-cli
redis-cli is a simple command-line tool to interact with redis database.
To switch your context into the RS container of node 1 in cluster 1, run:
$ docker exec -it rp1_node1 bash
To use redis-cli on port 12000, run:
$ redis-cli -p 12000
Store and retrieve a key in the database to test the connection with these commands:
set key1 123
The output of the command looks like this:
127.0.0.1:12000> set key1 123 OK 127.0.0.1:12000> get key1 "123"
exitto exit the redis-cli context and enter
exitagain to exit the RS container of node 1 in cluster 1.
To see that the key replicated to cluster 2, repeat the steps to switch your context into the RS container of node 1 in cluster 2, run the redis-cli and retrieve key1.
The output of the commands looks like this:
$ docker exec -it rp2_node1 bash $ redis-cli -p 12000 127.0.0.1:12000> get key1 "123"
Connecting Using Hello World Application in Python
A simple python application running on the host machine can also connect to the database.
Note: Before you continue, you must have python and redis-py (python library for connecting to Redis) configured on the host machine running the container.
In the command-line terminal, create a new file called "redis_test.py"
$ vi redis_test.py
Paste this code into the "redis_test.py" file.
This application stores a value in key1 in cluster 1, gets that value from key1 in cluster 1, and gets the value from key1 in cluster 2.
import redis rp1 = redis.StrictRedis(host='localhost', port=12000, db=0) rp2 = redis.StrictRedis(host='localhost', port=12002, db=0) print ("set key1 123 in cluster 1") print (rp1.set('key1', '123')) print ("get key1 cluster 1") print (rp1.get('key1')) print ("get key1 from cluster 2") print (rp2.get('key1'))
To run the "redis_test.py" application, run:
$ python redis_test.py
If the connection is successful, the output of the application looks like:
set key1 123 in cluster 1 True get key1 cluster 1 b'123' get key1 from cluster 2 b'123'