Back to Redis

redis-rb guide (Ruby)

content/develop/clients/ruby/_index.md

latest1.6 KB
Original Source

redis-rb is the Ruby client for Redis. The sections below explain how to install redis-rb and connect your application to a Redis database.

redis-rb requires a running Redis server. See [here]({{< relref "/operate/oss_and_stack/install/" >}}) for Redis Open Source installation instructions.

Install

To install redis-rb, run the following command:

bash
gem install redis

Connect and test

Connect to localhost on port 6379:

{{< clients-example set="landing" step="connect" lang_filter="Ruby" description="Foundational: Connect to a Redis server and establish a client connection" difficulty="beginner" >}} {{< /clients-example >}}

Store and retrieve a simple string.

{{< clients-example set="landing" step="set_get_string" lang_filter="Ruby" description="Foundational: Set and retrieve string values using SET and GET commands" difficulty="beginner" >}} {{< /clients-example >}}

Store and retrieve a dict.

{{< clients-example set="landing" step="hash_operations" lang_filter="Ruby" description="Foundational: Store and retrieve hash data structures using HSET and HGETALL" difficulty="beginner" >}} {{< /clients-example >}}

Close the connection when you're done.

{{< clients-example set="landing" step="close" lang_filter="Ruby" description="Foundational: Properly close a Redis client connection to release resources" difficulty="beginner" >}} {{< /clients-example >}}

More information

The GitHub repository for redis-rb has a set of examples and further information about using redis-rb.