{
  "id": "connect",
  "title": "Connect to the server",
  "url": "https://redis.io/docs/latest/develop/clients/ioredis/connect/",
  "summary": "Connect your Python application to a Redis database",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-04-01T08:10:08-05:00",
  "page_type": "content",
  "content_hash": "70419859eb70c5354743a9ceb8ecb69e083d70311f009cb8b1b71c9bdbc23950",
  "sections": [
    {
      "id": "basic-connection",
      "title": "Basic connection",
      "role": "overview",
      "text": "Connect to localhost on port 6379:\n\n[code example]\n\nYou can also specify a full set of connection options:\n\n[code example]\n\nStore and retrieve a simple string.\n\n[code example]"
    },
    {
      "id": "connect-to-a-redis-cluster",
      "title": "Connect to a Redis cluster",
      "role": "content",
      "text": "To connect to a Redis cluster, use `Redis.Cluster()`, passing an array of\nendpoints.\n\n[code example]"
    },
    {
      "id": "connect-to-your-production-redis-with-tls",
      "title": "Connect to your production Redis with TLS",
      "role": "content",
      "text": "When you deploy your application, use TLS and follow the [Redis security]() guidelines.\n\n[code example]"
    }
  ],
  "examples": [
    {
      "id": "basic-connection-ex0",
      "language": "js",
      "code": "const redis = new Redis();",
      "section_id": "basic-connection"
    },
    {
      "id": "basic-connection-ex1",
      "language": "js",
      "code": "const redis = new Redis({\n  port: 6379,\n  host: \"127.0.0.1\",\n  username: \"default\",\n  password: \"my-password\",\n  db: 0,\n});",
      "section_id": "basic-connection"
    },
    {
      "id": "basic-connection-ex2",
      "language": "js",
      "code": "await redis.set('foo', 'bar');\nconst value = await redis.get('foo');\nconsole.log(value); // >>> bar",
      "section_id": "basic-connection"
    },
    {
      "id": "connect-to-a-redis-cluster-ex0",
      "language": "js",
      "code": "const redis = new Redis.Cluster([\n    {\n        host: '127.0.0.1',\n        port: 6380,\n        password: 'my-password',\n        username: 'default',\n    },\n    {\n        host: '127.0.0.1',\n        port: 6381,\n        password: 'my-other-password',\n        username: 'default',\n    },\n    // ...\n]);",
      "section_id": "connect-to-a-redis-cluster"
    },
    {
      "id": "connect-to-your-production-redis-with-tls-ex0",
      "language": "js",
      "code": "const redis = new Redis({\n  host: \"localhost\",\n  //...\n  tls: {\n    key: readFileSync('./redis_user_private.key'),\n    cert: readFileSync('./redis_user.crt'),\n    ca: fs.readFileSync('./redis_ca.pem'),\n  },\n});",
      "section_id": "connect-to-your-production-redis-with-tls"
    }
  ]
}
