Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FLUSHALL and FLUSHDB commands on redis return "unk command"

Tags:

redis

To flush redis, the FLUSHALL command is to be used.

Using Redis 2.6.16, when I tried both FLUSHALL and FLUSHDB commands while using redis-cli, I got an unknown command error. Other commands work fine.

a) What is going wrong with the FLUSH* commands?

b) Is a workaround to do a shutdown of Redis, then delete the rdb file? (I believe so)

UPDATE:

No, we never solved this.

(The only known solution is to use step 'b' above)

like image 457
Jonesome Reinstate Monica Avatar asked Apr 02 '14 14:04

Jonesome Reinstate Monica


3 Answers

It could be that your Redis configuration has renamed some commands to prevent your database from being accidentaly deleted.

Look for the following lines in your redis.conf:

rename-command FLUSHDB ""
rename-command FLUSHALL ""
like image 56
Bernat Avatar answered Oct 16 '22 16:10

Bernat


Redis official Helm chart by default disables FLUSHDB and FLUSHALL commands. In this case, it is not specified in any of the redis.conf inside the containers, so you need to specify it in your Redis YAML:

master:
  disableCommands: []
like image 25
Camilo Sampedro Avatar answered Oct 16 '22 15:10

Camilo Sampedro


I was using Helm and didn't want to go through reinstalling it, so I worked around this issue by modifying the configmap that Helm generates to contain the config.

CONFIGMAP=<<value of common.names.fullname>>-configuration
kubectl edit cm $CONFIGMAP

You should see something like:

  master.conf: |-
    dir /data
    # User-supplied master configuration:
    rename-command FLUSHDB ""
    rename-command FLUSHALL ""
    # End of master configuration
  redis.conf: |-
    # User-supplied common configuration:
    # Enable AOF https://redis.io/topics/persistence#append-only-file
    appendonly yes
    # Disable RDB persistence, AOF persistence already enabled.
    save ""
    # End of common configuration
  replica.conf: |-
    dir /data
    slave-read-only yes
    # User-supplied replica configuration:
    rename-command FLUSHDB ""
    rename-command FLUSHALL ""
    # End of replica configuration

Remove lines beginning with rename-command so it looks more like this:

  master.conf: |-
    dir /data
    # User-supplied master configuration:
    # End of master configuration
  redis.conf: |-
    # User-supplied common configuration:
    # Enable AOF https://redis.io/topics/persistence#append-only-file
    appendonly yes
    # Disable RDB persistence, AOF persistence already enabled.
    save ""
    # End of common configuration
  replica.conf: |-
    dir /data
    slave-read-only yes
    # User-supplied replica configuration:
    # End of replica configuration

Restart the redis pods

kubectl delete pods $(kubectl get pods | grep redis | awk {'print $1'})

Now exec into the master pod and flush all

kubectl exec redis-master-0 -- redis-cli FLUSHALL
OK

Be aware that you will have to do this again if you reinstall your Helm release if you want to use FLUSHALL or FLUSHDB again.

Update: Although this works, when you go to reinstall your helm release the pods will go into crashloopbackoff because they will see in the history that the commands you ran don't exist, so you will have to go through this again to get the pods to run. Probably best to go with @camilo-sampedro's answer in this case.

like image 1
saranicole Avatar answered Oct 16 '22 15:10

saranicole