{
  "id": "connect",
  "title": "Connect to your Active-Active databases",
  "url": "https://redis.io/docs/latest/operate/rs/7.8/databases/active-active/connect/",
  "summary": "How to connect to an Active-Active database using redis-cli or a sample Python application.",
  "content": "\nWith the Redis database created, you are ready to connect to your\ndatabase to store data. You can use one of the following ways to test\nconnectivity to your database:\n\n- Connect with redis-cli, the built-in command-line tool\n- Connect with a _Hello World_ application written in Python\n\nRemember we have two member Active-Active databases that are available for connections and\nconcurrent reads and writes. The member Active-Active databases are using bi-directional\nreplication to for the global Active-Active database.\n\n\n\n### Connecting using redis-cli {#connecting-using-rediscli}\n\nredis-cli is a simple command-line tool to interact with redis database.\n\n1. To use redis-cli on port 12000 from the node 1 terminal, run:\n\n    ```sh\n    redis-cli -p 12000\n    ```\n\n1. Store and retrieve a key in the database to test the connection with these\n    commands:\n\n    - `set key1 123`\n    - `get key1`\n\n    The output of the command looks like this:\n\n    ```sh\n    127.0.0.1:12000\u003e set key1 123\n    OK\n    127.0.0.1:12000\u003e get key1\n    \"123\"\n    ```\n\n1. Enter the terminal of node 1 in cluster 2, run the redis-cli, and\n   retrieve key1.\n\n    The output of the commands looks like this:\n\n    ```sh\n    $ redis-cli -p 12000\n    127.0.0.1:12000\u003e get key1\n    \"123\"\n    ```\n\n### Connecting using _Hello World_ application in Python\n\nA simple python application running on the host machine can also connect\nto the database.\n\n\nBefore you continue, you must have python and\n[redis-py](https://github.com/andymccurdy/redis-py#installation)\n(python library for connecting to Redis) configured on the host machine\nrunning the container.\n\n\n1. In the command-line terminal, create a new file called \"redis_test.py\"\n\n    ```sh\n    vi redis_test.py\n    ```\n\n1. Paste this code into the \"redis_test.py\" file.\n\n    This application stores a value in key1 in cluster 1, gets that value from\n    key1 in cluster 1, and gets the value from key1 in cluster 2.\n\n    ```py\n    import redis\n    rp1 = redis.StrictRedis(host='localhost', port=12000, db=0)\n    rp2 = redis.StrictRedis(host='localhost', port=12002, db=0)\n    print (\"set key1 123 in cluster 1\")\n    print (rp1.set('key1', '123'))\n    print (\"get key1 cluster 1\")\n    print (rp1.get('key1'))\n    print (\"get key1 from cluster 2\")\n    print (rp2.get('key1'))\n    ```\n\n1. To run the \"redis_test.py\" application, run:\n\n    ```sh\n    python redis_test.py\n    ```\n\n    If the connection is successful, the output of the application looks like:\n\n    ```sh\n    set key1 123 in cluster 1\n    True\n    get key1 cluster 1\n    \"123\"\n    get key1 from cluster 2\n    \"123\"\n    ```\n",
  "tags": ["docs","operate","rs"],
  "last_updated": "2026-04-01T08:10:08-05:00"
}

