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 Memory Usage
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 Memory Usage

Introduction to Redis Memory Usage

Redis memory usage command will report the number of bytes of memory required for its key and value to store the data in memory. This command shows the memory in bytes which was required by the specified key. Reported usage will define the total memory allocations for administrative and data overheads that were required by its key and value. Memory usage defines the total memory required for execution commands.

Redis nested data types contain the sample options that we provide, with the count defined as nested sample values of number. By default, we set this option to 5. We use samples as 0 to sample all nested values. As we all know, redis is a data store that stores data in memory. Storing data in memory will improve database performance by storing data in memory.

While storing data in memory it improves the performance, suppose data grows then it becomes very difficult to handle the same. Adding the RAM is more expensive as compared to add the disk space. Size and storage have an impact on database systems, it is defined in memory database.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Redis Memory Usage

Key Takeaways

  • Redis memory usage is used to check the usage of memory based on the key that we defined or created in the redis server.
  • We can also check the memory usage in the redis server of the specified database and all key which was present in the redis server.

How do I Check my Redis Memory Usage?

In Redis, the memory usage command will report how many bytes are required to store the key and value. The reported memory specifies the amount of memory required to store the data. To check the redis memory usage, we must first login to the redis server using the redis-cli command. The below example shows how we can connect to the redis server.

Command:

# redis-cli

Output:

Redis Memory Usage - redis cli command

After login into the redis server now we are executing the info memory command to check the memory usage of the redis server.

Command:

INFO memory

Output:

info memory

Redis Memory Usage 3

While executing the info memory command it will show the details of the used memory and other all the details. We can also define the usage of memory by using the memory stats command as follows.

Command:

MEMORY stats

Output:

memory stats command

Redis Usage of Memory

Redis Memory Command

In the below example, we are executing the redis memory command by using the redis-cli command. To execute the redis memory command we are using redis-cli command as follows.

Command:

# redis-cli info memory

Output:

Executing Redis Memory Usage

Redis Info Memory

Below is the important parameter of the redis memory usage command. It will show all the details of the redis command parameter.

  • Used memory – This entry defined the total memory size allocated to the redis server. The value of this entry is specified in bytes.
  • Used memory human – This entry in the redis memory command shows the used memory value in a human-readable format.
  • Used memory rss – This entry shows the total number of bytes expressed by the specified operating system.
  • Used memory peak – It will show the total number of bytes consumed by the server of redis.
  • Used memory peak human – It is similar to the used memory peak entry, which we are defining in a human-readable format.

Instead of the above entries, there are other multiple entries defined in the redis memory command. We can also use the memory stats command in redis to find the usage of redis memory.

Redis Memory All Keys

We are using two commands to define the redis memory of all keys or specified keys. The below command shows how we can find the redis memory of all keys.

1. DB size

This command shows the total number of keys contained in a specified database. It will show all the keys present in the database. The below example shows how we can find the number of keys as follows.

Command:

# redis-cli -n 0 dbsize

Output:

DB size

By executing the above command, we can see that there are 49 keys displayed. It will display the total number of keys in the specified database with index zero. So we can say that the above DB contains a total of 50 keys.

2. Info keyspace

This command is used to show the information regarding all the keys present on the database server. It will show details like keys, their expiration, and avg_ttl.

Command:

# redis-cli info keyspace

Output:

Info keyspace

We can also use the memory usage command to see the number of bytes consumed by the specified key as follows. In the below example, we are finding the memory usage of the redis_mem key.

Command:

SET redis_mem val
MEMORY usage redis_mem

Output:

memory usage of redis_mem key

Redis Memory Analysis

Redis memory analysis will help us to analyze the redis database memory which is used to reduce memory use and improves the performance of the application.

In redis memory analysis is done using two ways:

  • Online mode
  • Offline mode

In online mode, redis downloads the rdb file from our connected instances and analyze the same for creating the temp file which required all the keys and metadata.

Redis Memory Usage - Temp file

The offline mode in Redis will analyze its backup file, which is either present on the s3 bucket or not. Redis insight is accepting rdb files that were provided in order to analyze all of the information required from the files and our Redis instance. We require read-only permission to analyze the backup file that was stored in S3.

either present on the s3 bucket or not

Examples of Redis Memory Usage

Below example shows redis memory usage as follows:

Example #1

In the below example, we are finding the memory usage of the specified key as follows. We are creating the key name as redis_memory.

Command:

SET redis_memory val12
MEMORY usage redis_memory

Output:

Rspecified key

Example #2

In the below example, we are adding another value in the same key defined in the above example and checking the memory usage.

Command:

SET redis_memory val13
MEMORY usage redis_memory

Output:

adding another value in same key

Example #3

In the below example, we are finding all the usage of all the keys from the redis server by using the following command as follows.

Command:

info memory

Output:

Usage of keys

Finding all Usage

FAQ

Given below are the FAQs mentioned:

Q1. How can we analyze the memory in redis?

Answer: We can analyze the memory by using two modes. The first mode is online mode and another mode is offline mode.

Q2. What is the use of memory usage command in redis?

Answer: The memory usage command is used to determine how much memory has been used from a specific or all keys.

Q3. What is the use of the info memory command in redis?

Answer: The info memory command is used to display all of the information about redis memory. It will display the used memory of the redis server.

Conclusion

Redis nested data types will contain the sample options that we are providing, with the count defined as nested sample values of number. The Redis memory usage command will report the number of bytes of memory required for its key and value to be stored in memory.

Recommended Articles

This is a guide to Redis Memory Usage. Here we discuss the introduction, redis memory command, all keys, analysis, 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