Subscribe to get my new tutorials in your inbox.

Useful Redis Commands for beginners

Useful Redis Commands for beginners

Redis is an open-source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. It is highly reliable, scalable, and has high availability. In this article, we look at some useful Redis commands for beginners.

Redis can be used to cache content . For eg. — database queries that are supposed to be used by users, for eg. Flight Search Results (of course with an expiry time), static content like HTML, JS, CSS. Redis is also highly used as a Session Store for users authorizations. Unique user sessions are stored in Redis. Rather than making roundtrips to Databases on the disk, reading and writing user sessions in Redis is faster.

Useful Redis Commands for beginners

Here are a few useful commands that you will be using very commonly,

1. Get All Keys

keys *

2. Get a particular key’s value

get key_name

3. Set a key with a value

set key_name value

4. Delete a key

del key_name

5. Set key with expiry in seconds. (Expire after 60secs)

set key_name value EX 60

You can also use ex in place of EX.

6. Set key with expiry in milliseconds. (Expire after 6secs = 6000ms)

set key_name value PX 6000

You can also use px in place of PX.

7. Flush the Database. Kill all keys.


8. Get Database size. Total no of active keys


9. Check expiry time left for a key. In seconds.

ttl key_name

What next?

Watch my video on how to set expiry to Redis keys. I cover the steps that you can use to expire your Redis cache after a defined time. Watch here.


Redis CLI Commands – link.

If you enjoyed this post and want similar articles to be delivered to your inbox directly, you can subscribe to my newsletters. I send out an email every two weeks with new articles, tips & tricks, news, free materials. No spamming, of course.

Write a Comment

Your email address will not be published. Required fields are marked *