Redis Client and Config Command Tutorial PART 1
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.
- 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.
CONFIG GET * command will result in an output that resembles the following:
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:
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:
Now the default value can be changed using the following code:
127.0.0.1:6379- CONFIG GET lua-time-limit
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:
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:
Redis COMMAND Command Example
The following code will use the Redis COMMAND function in a practical example:
7) 1) "setrange"
2) (integer) 4
3) 1) write
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 –
- Number of parameters –
- Nested array reply of command flags –
1) write 2) denyoom
- First key in arg list –
- Last key in arg list –
- The repeating keys –
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:
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:
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:
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:
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’:
Note that Redis returned “OK” to indicate the client connected to port 53357 was terminated.
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