Redis Client and Config Command Tutorial PART 1

Introduction

This is part one of a Redis client config command tutorial explaining the basic of Redis client and configuration commands. The Redis client config command options are useful for obtaining the configuration parameters of a Redis server. While not all the configuration parameters are supported in earlier versions of Redis, version 2.6 is able to read the entire configuration of a server with these command options.

Prerequisites

  • An understanding of part one of this tutorial series.

Redis CONFIG command

This section will explain the various CONFIG command options.

Redis CONFIG GET *

  • This CONFIG GET* command uses a wild card to show the available options for Redis configuration.

Executing the: CONFIG GET * command will result in an output that resembles the following:

127.0.0.1:6379- CONFIG GET *
1) "dbfilename"
2) "dump.rdb"
3) "requirepass"
4) ""
5) "masterauth"
6) ""
7) "unixsocket"
8) ""
9) "logfile"
10) ""
11) "pidfile"
12) ""
13) "maxmemory"
14) "0"

The above results shows the Redis configuration within the host system. Note that this is an abbreviated list as the full result was roughly 130 lines long.

Redis CONFIG GET -expression- Example

The following code shows how to use an expression within the CONFIG GET command:

127.0.0.1:6379- CONFIG GET *max-*-entries*
1) "hash-max-ziplist-entries"
2) "512"
3) "set-max-intset-entries"
4) "512"
5) "zset-max-ziplist-entries"
6) "128"

Note the Redis server returns a result with information that matches the specified expression.

Redis CONFIG SET Example

To obtain a better understanding of how this command functions, a specific option is used as a reference in the following command:

127.0.0.1:6379- CONFIG GET lua-time-limit
1) "lua-time-limit"
2) "5000"

Now the default value can be changed using the following code:

27.0.0.1:6379- CONFIG SET lua-time-limit 6000
OK
127.0.0.1:6379- CONFIG GET lua-time-limit
1) "lua-time-limit"
2) "6000"
127.0.0.1:6379-

This also shows the settings can be changed at runtime.

Redis INFO Command Example

This Redis command provides all of the info on the server:

127.0.0.1:6379- INFO
# Server
redis_version:3.2.100
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:dd26f1f93c5130ee
redis_mode:standalone
os:Windows
arch_bits:64
multiplexing_api:WinSock_IOCP
process_id:1396
run_id:7c71fb5adb5c2d98141be3ed7d792e2a19f2eb58
tcp_port:6379
uptime_in_seconds:3274
uptime_in_days:0
hz:10
lru_clock:12747479
executable:C:\redis\redis-server.exe
config_file:

# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

Here it returns the details for both the client and server. Note that the result are categorized for clarity and only a partial result is displayed.

The selection can also be trimmed down using a specific option. In this case the CPU is used with the following command:

127.0.0.1:6379- INFO CPU
# CPU
used_cpu_sys:0.08
used_cpu_user:0.14
used_cpu_sys_children:0.00
used_cpu_user_children:0.00
127.0.0.1:6379-

Redis COMMAND Command Example

The following code will use the Redis COMMAND function in a practical example:

127.0.0.1:6379- COMMAND
7) 1) "setrange"
2) (integer) 4
3) 1) write
2) denyoom
4) (integer) 1
5) (integer) 1
6) (integer) 1

Again, as the result is very long, the result shown here is a truncated list.

Referring back to part one of this tutorial, the COMMAND function will return the following six sub-results:

  • Command name – setrange
  • Number of parameters – (integer) 4
  • Nested array reply of command flags – 1) write 2) denyoom
  • First key in arg list – (integer) 1
  • Last key in arg list – (integer) 1
  • The repeating keys – (integer) 1

Note that there are 172 commands in this particular server.

The following code can also be used to find a particular command:

COMMAND INFO readonly

The output should resemble the following:

127.0.0.1:6379- COMMAND INFO readonly
1) 1) "readonly"
2) (integer) 1
3) 1) fast
4) (integer) 0
5) (integer) 0
6) (integer) 0

The following code can also be used to count the number of commands in the server:

127.0.0.1:6379- COMMAND COUNT
(integer) 172

Redis CLIENT Command Example

This section demonstrates how to use the Redis CLIENT command with a practical example.

Redis CLIENT LIST example

Begin with the CLIENT LIST by executing the following code to list currently connected clients:

127.0.0.1:6379- CLIENT LIST
id=2 addr=127.0.0.1:52868 fd=9 name= age=4490 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=18446744073709523520 events=r cmd=client

This shows there is only one client connected to the server, however, this number will grow as more clients connect.

Redis CLIENT KILL Command Example

This section will cover how to close a client connection.

First, confirm multiple clients are connected to the server by executing the following code:

127.0.0.1:6379- CLIENT LIST
id=2 addr=127.0.0.1:52868 fd=9 name= age=4983 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=18446744073709523520 events=r cmd=client
id=3 addr=127.0.0.1:53357 fd=10 name= age=19 idle=19 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=18446744073709537584 events=r cmd=command

This shows there are two clients connected to ports ‘52868’ and ‘53357’.

The following code would be used to close the connection of the client connected to port ‘53357’:

27.0.0.1:6379- CLIENT KILL 127.0.0.1:53357
OK

Note that Redis returned “OK” to indicate the client connected to port 53357 was terminated.

Conclusion

This was part one of a Redis client config command tutorial explaining the basics of Redis client and configuration commands. This Redis client config command tutorial specifically covered the Redis configuration command options and provided examples for the Redis config get, the config set, the info command, client command the client list and client kill commands. Remember that due to the length of the results, the lists in the examples in this tutorial have been abbreviated.

Pilot the ObjectRocket Platform Free!

Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.

Get Started

Keep in the know!

Subscribe to our emails and we’ll let you know what’s going on at ObjectRocket. We hate spam and make it easy to unsubscribe.