Connect to AWS ElastiCache (Redis) with redis-cli

Photo by Lucas Hein on Unsplash. Logo added by Kees C. Bakker

This week I needed to query an ElastiCache instance on AWS - which is Amazons version of Redis. I could not find a decent free client to query this remote dictionary, so I ended up using redis-cli on Ubuntu. Turns out: Redis is a wonderful and powerful system to work with.

Installation of redis-cli

You can install the Redis CLI on Debian based systems (Ubuntu) like with the APT package tool. We'll update and upgrade our packages, so we know we have the latest version:

sudo apt-get -y update; \
sudo apt-get -y upgrade; \
sudo apt-get -y install redis-tools; \
redis-cli --version

Note: this will install the Redis tools, not the Redis server.

Connect to your ElastiCache

You can now connect to your ElastiCache using the -h option. You can use -a to specify a password.

redis-cli -h

If you run on a different port, you can specify that port with the -p option or specify the entire url with -u like this:

redis-cli -u redis://

Useful queries

Here are some ways of querying your Redis instance:

# list all keys spaces
echo INFO keyspace | redis-cli -h

# list all keys inside the Redis instance
redis-cli -h --scan

# list all keys inside a Redis DB2
redis-cli -h -n 2 --scan

# lists the keys that are big
redis-cli -h --bigkeys

# counts the number of keys:
echo DBSIZE | redis-cli -h

The INFO command has some nice features.

Further reading

This might also interest you: