Redis Client and Config Command Tutorial Part 2
If you’re getting started with Redis, two important commands to know are the CLIENT and CONFIG commands. This second installment of our two-part series will pick up where we left off in our overview of Redis commands. In this article, we’ll provide a Redis CLIENT and CONFIG command tutorial, providing examples of how to use both of these commands.
Be sure you’ve read the first part of the tutorial series before beginning this second installment.
Redis CONFIG command
In this section, we’ll continue our look at all the variations available for the CONFIG command.
Redis CONFIG GET *
This Redis CONFIG command uses a wild card to show the available options for a Redis configuration. If we use the command
CONFIG GET *, our output will look like the following:
This output shows the Redis configuration for the host system. For the purposes of this tutorial, we’re just showing you a partial result of the command as the full set of results contains up to 130 lines.
Redis CONFIG GET
Next, we’ll show you how to use different expressions in conjunction with the CONFIG GET command. Here’s a simple example:
We can see that the Redis server will return results containing information that matches the specified expression.
Redis CONFIG SET Example
To understand this command, it’s best to start by using GET to retrieve a certain option as a point of reference:
We can change this option’s default value using the following code:
127.0.0.1:6379> CONFIG GET lua-time-limit
This example also proves that we can change the settings at runtime.
Redis INFO Command Example
The Redis INFO command will provide all available information about the server. The result set is categorized to make it more readable. In the following example, we’ll be showing you a partial result set since the full result set is quite large:
As you can see, the INFO command returns details for both the client and the server.
We can trim down our selection by using a specific option in the INFO command. In the following example, we’ll be using the CPU:
Redis COMMAND Command Example
In this section, we’ll show you an example of how to use Redis COMMAND:
7) 1) "setrange"
2) (integer) 4
3) 1) write
4) (integer) 1
5) (integer) 1
6) (integer) 1
This command returns another very lengthy result set, so we’ll be providing just a few lines of the results.
In Part 1 of this tutorial series, we mentioned that COMMAND will return six sub-results containing the following information:
- Command name –
- Number of parameters –
- Nested array reply of command flags –
1) write 2) denyoom
- First key in argument list –
- Last key in argument list –
- The repeating keys –
NOTE: In this particular server we have 172 commands
We can also get information on a particular COMMAND using the following syntax:
COMMAND INFO readonly
For this example, our output would look like the following:
1) 1) "readonly"
2) (integer) 1
3) 1) fast
4) (integer) 0
5) (integer) 0
6) (integer) 0
We can count how many commands are available on our server using the following command:
Redis CLIENT Command Example
In this section, we’ll look at some practical examples of how to use the Redis CLIENT command.
Redis CLIENT LIST example
Let’s start by using the CLIENT LIST command to retrieve a list of 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 output tells us that we only have one client connected to the server. As more clients connect to our server, this number will grow.
Redis CLIENT KILL Command Example
In this section, we’ll look into the command used to close a client connection.
First, let’s make sure that we have multiple clients connected to the server:
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
The output of the CLIENT LIST command confirms that we have two clients connected to ports ‘52868’ and ‘53357’. Let’s say we want to close the connection of the client connected to port ‘53357’. We can use the following command to kill it:
Redis returns a response of
OK, meaning that the client connected to port 53357 was terminated.
When you’re using Redis to store and manage data, it’s important to become familiar with some commonly-used commands. In this two-part article series, we showed how to use the CLIENT and CONFIG commands. With the instructions and examples provided in this Redis CLIENT and CONFIG command tutorial, you’ll be able to use any variation on these commands in your own Redis environment.
Pilot the ObjectRocket Platform Free!
Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.Get Started