{
  "schema_version": 2,
  "id": "develop/clients/ruby",
  "title": "redis-rb guide (Ruby)",
  "url": "https://redis.io/docs/latest/develop/clients/ruby/",
  "summary": "Connect your Ruby application to a Redis database",
  "aliases": [
    "/connect/clients/ruby/",
    "/clients/ruby/",
    "/develop/clients/redis-rb"
  ],
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-10-12T14:48:04+01:00",
  "children": [
    {
      "id": "develop/clients/ruby/connect",
      "summary": "Connect your Ruby application to a Redis database",
      "title": "Connect to the server",
      "url": "https://redis.io/docs/latest/develop/clients/ruby/connect/"
    },
    {
      "id": "develop/clients/ruby/queryjson",
      "summary": "Learn how to use Redis Search with JSON and hash documents.",
      "title": "Index and query documents",
      "url": "https://redis.io/docs/latest/develop/clients/ruby/queryjson/"
    },
    {
      "id": "develop/clients/ruby/vecsearch",
      "summary": "Learn how to index and query vector embeddings with Redis",
      "title": "Index and query vectors",
      "url": "https://redis.io/docs/latest/develop/clients/ruby/vecsearch/"
    },
    {
      "id": "develop/clients/ruby/transpipe",
      "summary": "Learn how to use Redis pipelines and transactions",
      "title": "Pipelines and transactions",
      "url": "https://redis.io/docs/latest/develop/clients/ruby/transpipe/"
    },
    {
      "id": "develop/clients/ruby/error-handling",
      "summary": "Learn how to handle errors when using redis-rb.",
      "title": "Error handling",
      "url": "https://redis.io/docs/latest/develop/clients/ruby/error-handling/"
    }
  ],
  "page_type": "content",
  "content_hash": "b43e70929db99f404b1824123c45406de3a1419fdda59a56b26db69e3a6bafb1",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "[redis-rb](https://github.com/redis/redis-rb) is the Ruby client for Redis.\nThe sections below explain how to install `redis-rb` and connect your application\nto a Redis database.\n\n`redis-rb` requires a running Redis server. See [here](https://redis.io/docs/latest/operate/oss_and_stack/install) for Redis Open Source installation instructions."
    },
    {
      "id": "install",
      "title": "Install",
      "role": "setup",
      "text": "To install `redis-rb`, run the following command:\n\n[code example]"
    },
    {
      "id": "connect-and-test",
      "title": "Connect and test",
      "role": "content",
      "text": "Connect to localhost on port 6379:\n\nFoundational: Connect to a Redis server and establish a client connection\n\n[code example]\n\n\n\n> [!NOTE]\n> redis-rb supports [connection URLs](https://redis.io/docs/latest/develop/clients/connection-urls#redis-rb-ruby) through the `url` option of `Redis.new`.\n> A URL can set the host, port, credentials, database, and whether to use TLS,\n> so you can use one instead of passing those options separately.\n\nStore and retrieve a simple string.\n\nFoundational: Set and retrieve string values using SET and GET commands\n\n[code example]\n\n\n\nStore and retrieve a dict.\n\nFoundational: Store and retrieve hash data structures using HSET and HGETALL\n\n[code example]\n\n\n\nClose the connection when you're done.\n\nFoundational: Properly close a Redis client connection to release resources\n\n[code example]\n\n\n\nTo connect to a cluster, through Redis Sentinel, or over TLS, see\n[Connect to the server](https://redis.io/docs/latest/develop/clients/ruby/connect)."
    },
    {
      "id": "more-information",
      "title": "More information",
      "role": "content",
      "text": "The\n[GitHub repository](https://github.com/redis/redis-rb) for `redis-rb` has a\nset of [examples](https://github.com/redis/redis-rb/tree/master/examples)\nand further information about using redis-rb."
    }
  ],
  "examples": [
    {
      "id": "install-ex0",
      "language": "bash",
      "code": "gem install redis",
      "section_id": "install"
    },
    {
      "id": "connect-and-test-ex0",
      "language": "ruby",
      "code": "require 'redis'\nr = Redis.new",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex1",
      "language": "ruby",
      "code": "r.set 'foo', 'bar'\nvalue = r.get('foo')\nputs value",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex2",
      "language": "ruby",
      "code": "r.hset 'user-session:123', 'name', 'John'\nr.hset 'user-session:123', 'surname', 'Smith'\nr.hset 'user-session:123', 'company', 'Redis'\nr.hset 'user-session:123', 'age', 29\n\nhash_value = r.hgetall('user-session:123')\nputs hash_value",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex3",
      "language": "ruby",
      "code": "r.close()",
      "section_id": "connect-and-test"
    }
  ]
}
