Redis strings commands are used to manage the string value of Redis storage. In this session, I will show you how to store string, how to retrieve and to delete string data form the Redis database.
Show all keys:
keys *
Set string value / Insert string data into redis:
Syntax:
set key value
Example:
set name "Art of CSE"
Get string data:
Syntax:
get key
Example:
get name
Delete string data:
Syntax:
del key
Example:
del name
Delete All Data:
FLUSHALL
Commands Description | Syntax | Example |
---|---|---|
Getting Substring of a string | GETRANGE key start end | GETRANGE name 0 2 |
Set the value and return its old value or nil for the new key | GETSET key value | GETSET name "The Art of CSE" |
Getting the value of multiple keys | MGET key1 key2 | MGET name email |
Store string with expire second | SETEX key seconds value | SETEX temp 5 "Temp value" |
Store string only if key doesn't exist | SETNX key value | SETNX id_number 23324 |
Getting the length of the string | STRLEN key | STRLEN name |
Store Multiple keys values | MSET key1 value1 key2 value2 | MSET one "Hello" two "World" |
Increment Integer Value by 1 | INCR key | INCR id_number |
Increment Integer value by a given amount | INCRBY key increment | INCRBY id_number 5 |
Decrement Integer Value by 1 | DECR key | DECR id_number |
Decrement Integer value by a given amount | DECRBY key decrement | DECRBY id_number 5 |
Append the value with the existing value | APPEND key value | APPEND name " Website" |