The Redis-cli utility is a complete Redis client and is used to manipulate data stored in the Redis database.
View brief documentation:
redis-cli -h
A Unix socket is used to connect to Redis. The command to connect looks like this:
redis-cli -s ~/.system/redis.sock
Key -s
must be specified, without it you cannot connect to a Unix socket.
After connecting to a Redis socket, the following popular commands are available for use:
keys '*'
key_
:keys key_*
You can use symbols in the pattern:
*
- any number of any characters.?
- any one character.example_data
with key key_example
:set key_example "example_data"
key_example
:get key_example
type key_example
key_example
on key_another_example
:rename key_example key_another_example
exists key_example
If the key exists, it will output 1
, if not - 0
.
key_example
:del key_example
ttl key_example
By default the output is -1
, which means there is no lifetime limitation.
expire key_example
multi
This mode is useful for executing multiple commands one at a time.
multi
:exec
If an error occurs while specifying commands, then all entries in the queue will be discarded.
key_example
:incr key_example
increment
:incrby key_example increment
key_example
:decr key_example
decrement
:decrby key_example decrement
key_example
text test_text
:append key_example "test_text"
strlen key_example
getrange key_example start end
The start and end of the range are specified instead of start
and end
... For example, for the line 1234567890
Command getrange key_example 2 6
willreturn 4567
... The characters are counted from 0.
start
:setrange key_example start "text"
For example, the line 1234567890
Command setrange key_example 2 «123»
will change to 1212367890
.
test
:rpush key_example "test"
start
and ending with the number stop
:lrange key_example start stop
llen key_example
lpop key_example
The commands are described in more detail in official documentation.