{
  "schema_version": 2,
  "id": "operate/rs/databases/active-active/connect",
  "title": "Connect to your Active-Active databases",
  "url": "https://redis.io/docs/latest/operate/rs/databases/active-active/connect/",
  "summary": "How to connect to an Active-Active database using redis-cli or a sample Python application.",
  "tags": [
    "docs",
    "operate",
    "rs"
  ],
  "last_updated": "2026-10-01T15:48:36+01:00",
  "page_type": "content",
  "content_hash": "ef3c5a9763efc5d9c4febf1b77c77a053420872f4197aeff7b9cc5bde05a1a86",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "With 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![](https://redis.io/docs/latest/images/rs/crdb-diagram.png)"
    },
    {
      "id": "connecting-using-rediscli",
      "title": "Connecting using redis-cli",
      "role": "content",
      "text": "redis-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    [code example]\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    [code example]\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    [code example]"
    },
    {
      "id": "connecting-using-_hello-world_-application-in-python",
      "title": "Connecting using _Hello World_ application in Python",
      "role": "content",
      "text": "A simple python application running on the host machine can also connect\nto the database.\n\n> [!NOTE]\n> Before 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\n> running the container.\n\n1. In the command-line terminal, create a new file called \"redis_test.py\"\n\n    [code example]\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    [code example]\n\n1. To run the \"redis_test.py\" application, run:\n\n    [code example]\n\n    If the connection is successful, the output of the application looks like:\n\n    [code example]"
    }
  ],
  "examples": [
    {
      "id": "connecting-using-rediscli-ex0",
      "language": "sh",
      "code": "redis-cli -p 12000",
      "section_id": "connecting-using-rediscli"
    },
    {
      "id": "connecting-using-rediscli-ex1",
      "language": "sh",
      "code": "127.0.0.1:12000> set key1 123\n    OK\n    127.0.0.1:12000> get key1\n    \"123\"",
      "section_id": "connecting-using-rediscli"
    },
    {
      "id": "connecting-using-rediscli-ex2",
      "language": "sh",
      "code": "$ redis-cli -p 12000\n    127.0.0.1:12000> get key1\n    \"123\"",
      "section_id": "connecting-using-rediscli"
    },
    {
      "id": "connecting-using-_hello-world_-application-in-python-ex0",
      "language": "sh",
      "code": "vi redis_test.py",
      "section_id": "connecting-using-_hello-world_-application-in-python"
    },
    {
      "id": "connecting-using-_hello-world_-application-in-python-ex1",
      "language": "py",
      "code": "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'))",
      "section_id": "connecting-using-_hello-world_-application-in-python"
    },
    {
      "id": "connecting-using-_hello-world_-application-in-python-ex2",
      "language": "sh",
      "code": "python redis_test.py",
      "section_id": "connecting-using-_hello-world_-application-in-python"
    },
    {
      "id": "connecting-using-_hello-world_-application-in-python-ex3",
      "language": "sh",
      "code": "set key1 123 in cluster 1\n    True\n    get key1 cluster 1\n    \"123\"\n    get key1 from cluster 2\n    \"123\"",
      "section_id": "connecting-using-_hello-world_-application-in-python"
    }
  ]
}
