Useful Redis Commands for beginners

0 0
Read Time:1 Minute, 16 Second

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.

flushdb

8. Get Database size. Total no of active keys

dbsize

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

ttl key_name

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %