EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials Redis Tutorial Redis gem
 

Redis gem

Updated February 17, 2023

Introduction to Redis gem

Redis gem is used to use the ruby with redis, at the time of using redis with the ruby we require a redis client of ruby. At the time of installing redis locally we are installing the same by using the apt command on ubuntu, but suppose we want to install redis with ruby then same time we are using gem and redis. We are installing the redis server by using gem.

 

 

Redis gem

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Key Takeaways

  • To interact with the ruby, we are using gem in redis. We are installing the redis by using gem for interacting the redis database with ruby.
  • We can use the redis gem on the docker container as well as on our system, by installing redis using gem.

What is Redis Gem?

As we know that we can directly interact with redis by using redis cli, but if suppose we want to work with redis by using ruby then we need to use gems.

Following are the gems available in redis as follows:

  • Oxblood
  • redic
  • redis-rb

Above are the gems available in redis, but the officially recommended gems for developers is redis-rb. By installing redis with gems we can connect to the server of redis and also start working by using the same. As we know that redis is an open-source and in-memory key-value data store that was commonly used in the primary database, queue, and message broker. Redis cache will deliver the sub milliseconds of response time which was enabling powerful and fast applications which are running in real-time.

We can run the redis on the docker container or we can also run the same on our machine. We are using the redis database in the cache system which was used in a server group by using the replication of primary and secondary.

How to Use Redis gem?

For using it we need to install the package of gem in our system first.

1. First, we are installing the gem in our system. We are installing gem by using the apt command as follows.

Command:

# apt install gem

Output:

Installing Redis gem

2. After installing the gem now in this step, we are installing the redis by using the gem. We can see that we are installing the redis version as 5.0.5. While installing this document in the below snap, we can see that it will parse the documentation.

Command:

# gem install redis

Output:

Redis gem - Installing the document

3. After installing the redis by using gems now in this step we are using the below code for connecting to the redis.

Code:

require 'redis'
redis = Redis.new (
    		:host => ‘ ’,
    		:port => 6379,
    		:password => 'Pass@123')

Output:

Redis gem - Code for connecting

4. After creating the connection code now in the below example, we are adding the redis set and get the command as follows. In the below example, we are creating the example.rb file.

Command:

require 'redis'
redis = Redis.new()
redis.set("redis_gem", "redis gem")
redis.get("redis_gem")

Output:

Redis gem - Creating the exapmle

5. While creating the example.rb file now in this step we are running this file using the ruby command.

Command:

# ruby example.rb

Output:

Redis gem - Ruby command

6. After executing the file by using the ruby command we can check the execution by using the monitor command as follows.

Command:

# redis-cli
MONITOR

Output:

Monitor command

Redis gem Versions

There is multiple version available for redis gem. Currently, the latest and most stable version is 5.0.5. We can check the redis gem version by using the following command. We can see that we have installed the latest version of redis gem i.e. 5.0.5.

Command:

gem list | grep redis

Output:

installed latest version

The version contains three parts i.e. major release, minor release, and patch release. We have the 5.0.5 version installed that first 5 show the major release, the middle zero is showing the minor release and the last 5 is showing the patch release.

Below is the redis gem version as follows:

  • 0.1: This version is released on 10th June 2009. After this release, another minor version and patches will release like 0.1, 0.1.1, 0.1.2, and 0.2.0.
  • 0.0: This version is released on 2nd April 2010. After this release, another minor version and patches will release like 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, and 1.0.7.
  • 0.0: This version is released on 14th May 2010. After this release, another minor version and patches will release like 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, 2.0.10, 2.0.11, 2.0.12, 2.0.13, 2.1.0, 2.1.1, 2.2.0, 2.2.1 and 2.2.2.
  • 0.0: This version is released on 23rd May 2012. After this release, another minor version and patches will release like 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.5, 3.0.6, 3.0.7, 3.1.0, 3.2.0, 3.2.1, 3.2.2, 3.3.0, 3.3.1, 3.3.2, 3.3.3, 3.3.4 and 3.3.5.
  • 0.0: This version is released on 25th August 2017. After this release, another minor version and patches will release like 4.0.1, 4.0.2, 4.0.3, 4.1.0, 4.1.1, 4.1.2, 4.1.3, 4.1.4, 4.2.0, 4.2.1, 3.2.2, 4.2.3, 4.2.4, 4.2.5, 4.3.0, 4.3.1, 4.4.0, 4.5.0, 4.5.1, 4.6.0, 4.7.0, 4.7.1 and 4.8.0.
  • 0.0: This version is released on 29th August 2022. After this release, another minor version and patches will release like 5.0.1, 5.0.2, 5.0.3, 5.0.4, and 5.0.5.

Examples of Redis gem

Given below are the examples mentioned:

Example #1

In the below example, we are connecting to the redis database and using the set and get command for creating the redis-rb file.

Command:

require 'redis'
redis = Redis.new()
redis.set("redis_gem_example", "redis gem_example")
redis.get("redis_gem_example")

Output:

Creating the redis-rb file

Ruby Redis Example

Redis gem example

Example #2

In the below example, we are connecting to the redis database and using the set command for creating the redis-rb file.

Command:

require 'redis'
redis = Redis.new()
redis.set("redis_gem_example", "redis gem_example")

Output:

set command

Ruby Redis gem example 1

Ruby Redis gem example 2

Example #3

In the below example, we are connecting to the redis database and using the hset command for creating the redis-rb file as follows.

Command:

require 'redis'
redis = Redis.new()
redis.hset("redis_gem_example", ”field1”, "redis gem_example")

Output:

using hset command

Redis gem - hset example

hset command

FAQ

Given below are the FAQs mentioned:

Q1. What is the use of redis gem?

Answer: It is basically used to use the ruby with the redis database. Without installing gem with redis we cannot use ruby in the redis database.

Q2. How many types of gems are available in redis?

Answer: In redis basically there are three types of gem available i.e. oxblood, redis, and redis-rb.

Q3. How can we check the execution of redis-rb file?

Answer: We are executing the redis-rb file by using the ruby and filename commands and we are checking the execution by using the monitor command.

Conclusion

It is used to use the ruby with redis, at the time of using redis with the ruby we required a redis client of ruby. The officially recommended gems for developers is redis-rb. By installing redis with gems we can connect to the server of redis and also start working by using the same.

Recommended Articles

This is a guide to Redis gem. Here we discuss the introduction, how to use redis gem? versions and examples respectively. You may also have a look at the following articles to learn more –

  1. Redis Get All Keys
  2. Redis GUI
  3. Redis Pubsub
  4. Redis Version

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW