Conflict-Free Replicated Databases (CRDBs) let you create replicated instances of your data between Redis Enterprise Software (RS) clusters. The participating clusters that host the instances can be in distributed geographic locations. Every instance of a CRDB can receive write operations, and all operations are synchronized to all of the instances.

Overview of the Steps to Create a CRDB

  1. Create a service account - On each participating cluster, create a dedicated user account with the Admin role.
  2. Confirm connectivity - Confirm network connectivity between the participating clusters.
  3. Create CRDB - Connect to one of your clusters and create a new CRDB.
  4. Add participating clusters - Add the participating clusters to the CRDB with the user credentials for the service account.
  5. Confirm CRDB Synchronization - Test writing to one cluster and reading from a different cluster.

Prerequisites

  • Two or more machines with the same version of RS installed
  • Network connectivity and cluster FQDN name resolution between all participating clusters
  • Network time service listener (ntpd) configured and running on each node in all clusters

Creating a CRDB

  1. To create service accounts, on each participating cluster:

    1. In your web browser, open the web UI of the cluster that you want to connect to in order to create the CRDB. By default, the address is: https://<RS_address>:8443
    2. Go to settings > team and click Add.
    3. Enter the name, email, and password for the user, select the Admin role, and click Save.

    Service Account Creation

  2. To make sure that there is network connectivity between the participating clusters, telnet on port 8080 from each participating cluster to each of the other participating clusters.

    $ telnet <target FQDN> 8080
  3. In your web browser, open the web UI of the cluster that you want to connect to in order to create the CRDB. By default, the address is: https://<RS_address>:8443

  4. In databases, click Add.

    If you do not have any databases on the node, you are prompted to create a database.

  5. In the Deployment box, select Geo-Distributed.

    new_geo-distrbuted

  6. Enter the name of the new CRDB and select from the options:

    Note -
    • The eviction policy can only be set to noeviction for CRDBs.
    • You cannot enable or disable database clustering after the CRDB is created.
    • Replication - We recommend that you use intra-cluster replication to create slave shards in each CRDB instance. The intercluster synchronization is most efficient when it reads from slave shards.
    • Participating Clusters - You must specify the URL of the clusters that you want to host CRDB instances and the admin user account to connect to each cluster.
      • In the Participating Clusters list, click Add to add clusters.
      • For each cluster, enter the URL for the cluster (http://<cluster_URL>:8080), and enter the credentials for the service account that you created.
    • In the Database clustering option, you can 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 so that you can use Multi-key commands without the limitations.
    • Causal Consistency - Causal Consistency in a CRDB guarantees that the order of operations on a specific key is maintained across all CRDB instances. To enable Causal Consistency for an existing CRDB, use the REST API.
    • SSL Authentication - You can enable SSL for communications between Participating Clusters. After you create the CRDB, you can enable SSL for the data access operations from applications just like regular Redis Enterprise databases.

      SSL for data access operations is a local setting on each cluster that only impacts the specific CRDB instance you are editing and does not apply automatically to all CRDB instances.

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.

crdb-diagram

Connecting Using redis-cli

redis-cli is a simple command-line tool to interact with redis database.

  1. To switch your context into the RS container of node 1 in cluster 1, run:

    $ docker exec -it rp1_node1 bash
  2. To use redis-cli on port 12000, run:

    $ redis-cli -p 12000
  3. Store and retrieve a key in the database to test the connection with these commands:

    • set key1 123
    • get key1

    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"
  4. Enter exit to exit the redis-cli context and enter exit again to exit the RS container of node 1 in cluster 1.

  5. 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.

  1. In the command-line terminal, create a new file called "redis_test.py"

    $ vi redis_test.py
  2. 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'))
  3. 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'