8.11. Redis CLI

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

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

View quick documentation:

redis-cli -h

With a connection string:

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

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

With host and port:

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

Instead 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 connection:

AUTH login "password"

Instead login and password use the Redis user credentials. If the login is not specified, authorization will be under the user by default.

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

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

Print all recorded keys:

keys '*'

Output all recorded keys from key_ In the title:

keys key_*

You can use symbols in the pattern:

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

Write data example_data with key key_example:

set key_example "example_data"

Получить данные, записанные ранее with key key_example:

get key_example

Get the type of data stored in the key key_example:

type key_example

Rename key from key_example on key_another_example:

rename key_example key_another_example

Check for the existence of a key key_example:

exists key_example

If the key exists, it will output 1, if not - 0.

Delete data and key key_example:

del key_example

Get key lifetime key_example:

ttl key_example

By default, the output is -1, which means there is no lifetime limitation.

Set key lifetime key_exampleand the data written in it, after which the key will be deleted:

expire key_example

Activate the mode of writing commands to the queue:


This mode is useful for executing multiple commands one at a time.

Execute all commands written to the queue after multi:


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

Инкремент, увеличение on единицу значения данных with key key_example:

incr key_example

Инкремент, увеличение значения данных with key key_example on число, указанное вместо increment:

incrby key_example increment

Декремент, уменьшение on единицу значения данных with key key_example:

decr key_example

Декремент, увеличение значения данных with key key_example on число, указанное вместо decrement:

decrby key_example decrement

Add text to the end of the data line test_text:

append key_example "test_text"

Length of the written data string 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 line 1234567890 command getrange key_example 2 6 willreturn 4567. Characters are counted from 0.

Replace the data written in the key, starting with the character under the number start:

setrange key_example start "text"

For example, the line 1234567890 command setrange key_example 2 «123» изменит on 1212367890.

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

rpush key_example "test"

List the elements of the list, starting with the element numbered start and заканчивая номером stop:

lrange key_example start stop

Get the number of items in a list:

llen key_example

Удалить первый элемент списка and получить данные следующего:

lpop key_example