redis-cli - is the Redis command line interface, a simple program that allows to send commands to Redis, and read the replies sent by the server, directly from the terminal.
In order to use the tool, you'll need SSH access to your account. ( If you do not have that yet, then please contact us and we'll get it sorted for you.)
You'll also need your Redis socket address, which you can find within cPanel >> Redis:
so if you know your cPanel username, you can just replace that accordingly and get it from here.
To communicate with Redis and make sure it's working properly, run:
redis-cli -s /home/USER/.kxcache/redis.sock PING
and it should respond with PONG:
Alright! We’ve connected to our very own Redis server and can start working with it.
To monitor the commands executed in Redis, run:
redis-cli -s /home/USER/.kxcache/redis.sock monitor
It will print all the commands received by a Redis instance:
1460100081.165665 [0 unix:/home/USER/.kxcache/redis.sock] "set" "foo" "bar"
1460100083.053365 [0 unix:/home/USER/.kxcache/redis.sock] "get" "foo"
It is possible to use to pipe the output, so you can monitor for specific patterns using tools such as grep.
Another useful command is: dbsize which returns the number of keys in the currently-selected database.
To use it, you'll first need to login to Redis:
redis-cli -s /home/USER/.kxcache/redis.sock
then select the database which you want to check (default is 0):
and run the command:
It should output the number of keys as integer.
Another great command is stat which which will enter continuous stats mode:
redis-cli -s /home/USER/.kxcache/redis.sock --stat
This is probably one of the lesser known features of redis-cli, and one very useful in order to monitor Redis instances in real time. To enable this mode, the --stat option is used. The output is very clear about the behavior of the CLI in this mode:
------- data ------ --------------------- load -------------------- - child -
keys mem clients blocked requests connections
22481 511.69M 3 0 549054 (+0) 71395
22481 511.75M 6 0 549083 (+29) 71401
22481 511.77M 7 0 549103 (+20) 71404
22481 511.79M 8 0 549115 (+12) 71406
22481 511.77M 7 0 549126 (+11) 71408
22481 511.71M 4 0 549132 (+6) 71409
22481 511.71M 4 0 549150 (+18) 71412
22481 511.94M 12 0 549191 (+41) 71421
Here we can see:
How many keys are set on the server.
The server's total memory usage.
The total number of clients connected or blocked.
The total number of requests the server has served.
The total current number of connections.
This command is useful to get an overview of the Redis server as a whole.
Finally, in order to flush Redis cache, you can use:
redis-cli -s /home/USER/.kxcache/redis.sock flushall
If you have any other interesting commands - let us know and we'll be happy to include these in the list!
Powered by WHMCompleteSolution