# Connect to AWS ElastiCache (Redis) with redis-cli

**Date:** 2020-01-26  
**Author:** Kees C. Bakker  
**Categories:** bash, Redis  
**Original:** https://keestalkstech.com/connect-to-aws-elasticache-redis-with-redis-cli/

![Connect to AWS ElastiCache (Redis) with redis-cli](https://keestalkstech.com/wp-content/uploads/2020/01/2020-01-26_1305.jpg)

---

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:

```sh
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](https://packages.ubuntu.com/bionic/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.

```sh
redis-cli -h my.url.to.redis.cache.amazonaws.com
```

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:

```sh
redis-cli -u redis://my.url.to.redis.cache.amazonaws.com:1234
```

## Useful queries

Here are some ways of querying your Redis instance:

```sh
# list all keys spaces
echo INFO keyspace | redis-cli -h my.url.to.redis.cache.amazonaws.com

# list all keys inside the Redis instance
redis-cli -h my.url.to.redis.cache.amazonaws.com --scan

# list all keys inside a Redis DB2
redis-cli -h my.url.to.redis.cache.amazonaws.com -n 2 --scan

# lists the keys that are big
redis-cli -h my.url.to.redis.cache.amazonaws.com --bigkeys

# counts the number of keys:
echo DBSIZE | redis-cli -h my.url.to.redis.cache.amazonaws.com
```

The [INFO command](https://redis.io/commands/info) has some nice features.

## Further reading

This might also interest you:
