8.5.14. Redis CLI

The utility is available by default on all shared and business hosting servers.

Redis CLI is a utility for working with Redis via a command line interface. A detailed description of all features is available in official documentation.

View brief documentation:

redis-cli -h

Using a connection string:

redis-cli -u redis://example.redis.tools:10000

Instead of redis://example.redis.tools:10000, use the connection string to the desired Redis instance copied from the control panel.

Using host and port:

redis-cli -h example.redis.tools -p 10000

Instead of example.redis.tools and 10000, use the host and port from the connection string to the desired Redis instance in the control panel.

Authorization after connecting:

AUTH login "password"

Instead of login and password, use the Redis user data. If no login is specified, authorization will be under the default user.

For hosting If Redis is ordered as a extra service, you must use a Unix socket to connect:

redis-cli -s ~/.system/redis.sock

Output all recorded keys:

keys '*'

Output all recorded keys with key_ in the name:

keys key_*

Symbols can be used in a pattern:

  • * — any number of any character.
  • ? — one of any character.

Write example_data with the key key_example:

set key_example "example_data"

Get the data previously written with the key_example key:

get key_example

Get the type of data stored in the key_example key:

type key_example

Rename the key from key_example to key_another_example:

rename key_example key_another_example

Check the existence of the key_example key:

exists key_example

If the key exists, a 1 will be output, if not, a 0 will be output.

Delete the data and the key_example key:

del key_example

Get the lifetime of the key key_example:

ttl key_example

The default output is -1, which means there is no lifetime limit.

Set the lifetime of the key_example key and the data recorded in it, after which the key will be deleted:

expire key_example

Activate the mode of writing commands to the queue:

multi

This mode is useful for alternately executing multiple commands.

Execute all commands queued after multi:

exec

If an error occurs while specifying commands, all entries in the queue will be reset.

Increment, increment by one the value of data with key key_example:

incr key_example

Increment, increase the value of data with key key_example by the number specified instead of increment:

incrby key_example increment

Decrement, decrement by one the value of data with key key_example:

decr key_example

Decrement, increment the value of data with key key_example by the number specified instead of decrement:

decrby key_example decrement

Add the text test_text to the end of the data string:

append key_example "test_text"

The length of the written string of data in the key:

strlen key_example

Get a specific character range of a string:

getrange key_example start end

The start and end of the range are specified instead of start and end. For example, for the string 1234567890 the command getrange key_example 2 6 will return 4567. The characters are counted from 0.

Replace the data written in the key starting with the character numbered start:

setrange key_example start "text"

For example, the string 1234567890 will be changed to 1212367890 by the command setrange key_example 2 "123".

Add a new item with the text test to the end of the list:

rpush key_example "test"

Output the list items starting from the item numbered start and ending with the number stop:

lrange key_example start stop

Get the number of list items:

llen key_example

Delete the first list item and get the data of the next one:

lpop key_example
Content