Show List

Redis commands and their usage

Redis commands are used to interact with the Redis server and manipulate the data stored in it. Redis supports a wide range of commands, each with a specific functionality. Here are some commonly used Redis commands and their usage with examples:

  1. SET key value - sets a key-value pair in Redis.

Example: SET name John

  1. GET key - retrieves the value of a key from Redis.

Example: GET name (returns "John")

  1. INCR key - increments the value of a key by 1.

Example: INCR counter (if counter has value 5, it will be incremented to 6)

  1. LPUSH key value - pushes a value to the beginning of a list.

Example: LPUSH mylist "Hello" (adds "Hello" to the beginning of mylist)

  1. RPUSH key value - pushes a value to the end of a list.

Example: RPUSH mylist "World" (adds "World" to the end of mylist)

  1. LPOP key - removes and returns the first element from a list.

Example: LPOP mylist (if mylist has values "Hello" and "World", it will return "Hello" and mylist will now have only "World")

  1. RPUSH key value - removes and returns the last element from a list.

Example: RPOP mylist (if mylist has value "World", it will return "World" and mylist will now be empty)

  1. SADD key member - adds a member to a set.

Example: SADD myset "Hello" (adds "Hello" to myset)

  1. SMEMBERS key - returns all the members of a set.

Example: SMEMBERS myset (if myset has values "Hello" and "World", it will return "Hello" and "World")

  1. ZADD key score member - adds a member with a score to a sorted set.

Example: ZADD myzset 1 "Hello" (adds "Hello" to myzset with a score of 1)

These are just a few examples of Redis commands. Redis supports many more commands for working with various data structures and performing other operations.


    Leave a Comment


  • captcha text