Sometimes I find myself needing to connect to a Redis instance from the command line. Normally during an incident where we need to manually invalidate some cache. This is how I do it.
It is important to not include the :port
part (e.g. :6379
) in the url as you get some weird error that doesn’t make it obvious that this is the issue.
Once you have run this command you will be connected to the Redis instance and can run any command you need to.
GET
Returns whatever is stored at key
DEL
Deletes whatever is stored at key
SETEX
Set with expiry
Manually pipe a large amount of data into a key
If you have a large amount of data that you wish to save to a specific key, the CLI might not let you. To get around this, you can pipe the data in using the following command (from your standard CLI, not from within the Redis CLI - i.e. you do not need to have connected to the Redis CLI first)
In this example, redis.txt
is a text file in the current working directory:
redis.txt
should contain the full command AND the payload. Make sure the payload is in the right format too (likely stringified). For example: