Hast Hast - 1 year ago 191
Linux Question

Flush specific Redis DB using a single command

In order to flush some specific redis database, I need to do the following:

  • Enter the Redis interactive CLI (
    > redis-cli

  • Select a database (
    > select 0

  • Flush the db (
    > flushdb

But is there a way to run these 2 interactive commands as a single shell command? I can only pass one command to the interactive application using the pipe:
"echo select 0" | redis-cli
, but not both of them.

Answer Source

You can select the database with the call to the cli using the -n switch.

For running more than one command, redirect a file instead of piping an echo, or feed the cli raw protocol with the --pipe switch.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download