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 CLI Commands
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 CLI Commands

Redis CLI Commands

Introduction to Redis CLI Commands

Redis command line interface is an initiative terminal program that is used to communicate commands between the user and the Redis server. It has main modes like interactive mode called read print loop where the user gives commands and gets replies and other command modes where Redis CLI comes into the picture and has added arguments where the reply is fetched to get standard output. In interactive mode, basic line editing functions are available in Redis CLI which gives a normal typing experience.

Key Takeaways

  • Redis can be operated using two modes, interactive and command mode.
  • Redis CLI command mode checks the latency of the Redis server.
  • It reviews the scheduler latency of the host machine.
  • It checks the stats on key hits using LRU workloads.
  • It uses escaped string values and quoted strings to delimit the arguments using whitespace characters.

Overview of Redis CLI Command

Redis CLI is an open-source, free, in-memory database that is used to save the data as key-value pairs. So by using Redis, there are many in-built commands with a CLI interface and it is easy to use. By using this there are many special modes to install. The user can simulate replicas and give the replica stream to which it is received as primary and can also look at the display status and latency of the Redis server. The user can request latency frequency and a sample of ASCII spectrogram. There is an in-built command for each operation that makes Redis a unique choice. In Redis, all sorts of data structures can be implied like a sorted set, hash, list, set, and strings. But no float data or integer can be included. The string commands enable the user to compute string numbers as values.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

How to Use Redis CLI Command?

To execute a Redis command and fetch the standard output at any terminal, the user can work on commands to segregate arguments.

$ Redis CLI INCR myname

Integer

The output of this command will be 6. Because the Redis reply can be given in any form like arrays, integers, strings, errors, nil, etc. The reply is executed between parentheses because the output can be used again as input to other commands or it signifies file redirection.

Redis CLI displays any extra information required for human readability to detect the standard output on the terminal. For all the other output, it will enable the raw output mode.

$ Redis-CLI INCR myname > /tmp / view.txt
$ cat /tmp/ view.txt

7

How does Redis CLI Command Work?

If Redis CLI gives any command, the whitespace characters delimit the arguments and interactive mode, and newline gives the command for execution and parsing. To make input string values, which have non-executable characters or whitespace, the user can use escaped strings or quoted ones. Quoted values should be enclosed in single or double quotation marks and escape values are used to print not executable characters.

The escape sequence has a backslash followed by escape characters. The double-quoted strings that support the escape sequence are \ ‘’ as double quote, \n as new line, \r as carriage return, \t as horizontal tab, /b as backspace, /a as alert.

Single quotes presume it as literal and enable the escape sequence, \’ as a single quote or \\ as backlash.

127.0.0.1:6379> SET myname "Hello\myWorld"
OK
127.0.0.1:6379> GET myname

Hello my world

Redis CLI Command Installation

These are the below steps to install Redis:

1. The system packages should be updated.

$sudo apt-get update

Then it should be upgraded and refresh the environment.

$ sudo apt –get upgrade

Redis CLI Commands 1

2. Install Redis package using.

$ sudo apt –get install Redis server

Redis CLI Commands 2

3. Start and enable the Redis service.

$ sudo systemctl enable Redis service
$ sudo systemctl start Redis service

Redis CLI Commands 3

4. Once the Redis is installed, check it by executing the CLI command.

$ Redis –CLI

The output should be like this:

127.0.0.1::6379 >

So, this is the port number and IP address of the Redis server.

Redis CLI Commands port number and IP address

5. Navigate to Redis CLI and execute all the Redis commands and check the database by using ping, to test that the server is up. If it is up, it gives output as PONG.

Redis CLI Commands database by using ping

6. Connect to Redis CLI using a custom port. Redis server can also be executed as the customized port in some instances. But if it is not given, the Redis CLI uses the default port as 6379.

7. Redis offers the user sixteen databases from 0 to 15 indexes. So, he can switch to the required database using the select command.

127.0.0.1.6379 > select 12

OK

Hence these are the steps to install Redis on the local machine.

Examples of Redis CLI

Here are the standard examples of Redis CLI. They are get and set, setex and psetex, setnx and setxx, del, append, strlen, setrange, getrange, incr, incrby, incrbyfloat, mset, mget, msetnx, decr, and decrby.

Use set to assign a value to key.

Use get to retrieve the value from a key.

127.0.0.1:6379 > SET site "educba"

OK

127.0.0.1:6379 > GET site

educba

If there is no key, the output will be nil.

If a key doesn’t exist, you’ll see “nil” as the output.

127.0.0.1:6379 > GET hike

nil

FAQ

Given below are the FAQs mentioned:

Q1. How to delete a key?

Answer: By using the DEL option, the user can delete a key and the output will signify how many keys are deleted.

Q2. How to check the Redis database?

Answer: The Redis server has a default 16 database and executes the Redis CLI config get the database. Using interactive mode, the number of the database is viewed within square braces.

Q3. How to check all the available Redis keys?

Answer: To view all the keys in the Redis data store, using keys commands, it follows the specific pattern and searches for all the keys that go with the given pattern. It is also done with an asterisk to get all the matching values.

Conclusion

Multiple operations can be executed with Redis CLI command mode which is time-saving and easy to use and manage. Hence it is efficient for higher dimensional data management.

Recommended Articles

This is a guide to Redis CLI Commands. Here we discuss the introduction, and how to use redis CLI command. working and examples. 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