Redis Strings (String)
Commands related to the Redis string data type are used to manage Redis string values. The basic syntax is as follows:
Syntax
redis 127.0.0.1:6379> COMMAND KEY_NAME
Example
redis 127.0.0.1:6379> SET tutorialprokey redis
OK
redis 127.0.0.1:6379> GET tutorialprokey
"redis"
In the above example, we used the SET and GET commands with the key tutorialprokey.
Redis String Commands
The table below lists commonly used Redis string commands:
Number | Command and Description |
---|---|
1 | SET key value <br>Sets the value of a key. |
2 | GET key <br>Gets the value of a key. |
3 | GETRANGE key start end <br>Returns a substring of the string value stored at key. |
4 | GETSET key value <br>Sets the string value of a key and returns its old value. |
5 | GETBIT key offset <br>Gets the bit at the specified offset in the string value stored at key. |
6 | MGET key1 [key2..] <br>Gets the values of all given keys. |
7 | SETBIT key offset value <br>Sets or clears the bit at the specified offset in the string value stored at key. |
8 | SETEX key seconds value <br>Sets the value and expiration of a key. |
9 | SETNX key value <br>Sets the value of a key only if the key does not exist. |
10 | SETRANGE key offset value <br>Overwrites part of the string value stored at key, starting at the specified offset. |
11 | STRLEN key <br>Returns the length of the string value stored at key. |
12 | MSET key value [key value ...] <br>Sets multiple key-value pairs simultaneously. |
13 | MSETNX key value [key value ...] <br>Sets multiple key-value pairs only if none of the keys exist. |
14 | PSETEX key milliseconds value <br>Similar to SETEX, but sets the expiration time in milliseconds. |
15 | INCR key <br>Increments the integer value stored at key by one. |
16 | INCRBY key increment <br>Increments the value stored at key by a given increment. |
17 | INCRBYFLOAT key increment <br>Increments the value stored at key by a given floating-point increment. |
18 | DECR key <br>Decrements the integer value stored at key by one. |
19 | DECRBY key decrement <br>Decrements the value stored at key by a given decrement. |
20 | APPEND key value <br>If the key already exists and is a string, the APPEND command appends the specified value to the end of the original value of the key. |
For more commands, please refer to: https://redis.io/commands