EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Redis Tutorial Redis gem
Secondary Sidebar
Redis Tutorial
  • Redis
    • Redis Pubsub
    • Redis GUI
    • Redis Database
    • Redis Get All Keys
    • Redis TTL
    • Redis EXPIRE
    • Redis Version
    • Redis EXPIRE
    • Redis List
    • Redis CLI Commands
    • Redis HSET
    • Redis FLUSHDB
    • Redis Key
    • Redis Persistence
    • Redis FLUSHALL
    • Redis pipeline
    • Redis SADD
    • Redis ZADD
    • Redis ZSET
    • Redis Get
    • Redis Replication
    • Redis Delete All Keys
    • Redis Use Cases
    • Redis HMSET
    • Redis Transactions
    • Redis Monitor
    • Redis HGET
    • Redis SETEX
    • Redis Rails
    • RedisJSON
    • Redis Get Key
    • Redis Auth
    • Redis gem
    • Redis Key Count
    • RedisTimeSeries
    • Redis Timeout
    • Redis LPUSH
    • Redis Architecture
    • Redis API
    • Redis Message Queue
    • Redis RPUSH
    • Redis Protocol
    • Redis Data Types
    • Redis Namespace
    • Redis ZRANGE
    • Redis Master Slave
    • Redis Memory Usage
    • Redis WATCH
    • Redis URL
    • Redis Key Value
    • Redis INCR
    • Redis EXISTS
    • Redis INFO
    • Redis HMGET
    • Redis Operator
    • Redis NOAUTH Authentication Required
    • Redis LRANGE
    • Redis RDB
    • Redis TLS
    • Redis HDEL
    • Redis WebSocket
    • Redis HGETALL
    • Redis GETSET
    • Node-RED WebSocket

Redis gem

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

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.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

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 => '[email protected]')

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
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - 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

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*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?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more