Redis strings commands are used for managing string values in Redis. Following is the syntax for using Redis string commands.

Syntax

redis 127.0.0.1:6379> COMMAND KEY_NAME 

Example

redis 127.0.0.1:6379> SET tutorialspoint redis 
OK 
redis 127.0.0.1:6379> GET tutorialspoint 
"redis" 

In the above example, SET and GET are the commands, while tutorialspoint is the key.

Redis Strings Commands

Following table lists some basic commands to manage strings in Redis.

Sr.NoCommand & Description
1SET key valueThis command sets the value at the specified key.
2GET keyGets the value of a key.
3GETRANGE key start endGets a substring of the string stored at a key.
4GETSET key valueSets the string value of a key and return its old value.
5GETBIT key offsetReturns the bit value at the offset in the string value stored at the key.
6MGET key1 [key2..]Gets the values of all the given keys
7SETBIT key offset valueSets or clears the bit at the offset in the string value stored at the key
8SETEX key seconds valueSets the value with the expiry of a key
9SETNX key valueSets the value of a key, only if the key does not exist
10SETRANGE key offset valueOverwrites the part of a string at the key starting at the specified offset
11STRLEN keyGets the length of the value stored in a key
12MSET key value [key value …]Sets multiple keys to multiple values
13MSETNX key value [key value …]Sets multiple keys to multiple values, only if none of the keys exist
14PSETEX key milliseconds valueSets the value and expiration in milliseconds of a key
15INCR keyIncrements the integer value of a key by one
16INCRBY key incrementIncrements the integer value of a key by the given amount
17INCRBYFLOAT key incrementIncrements the float value of a key by the given amount
18DECR keyDecrements the integer value of a key by one
19DECRBY key decrementDecrements the integer value of a key by the given number
20APPEND key valueAppends a value to a key

Leave a Reply

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