Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I flush all redis nodes through predis?

Tags:

redis

predis

I am trying to test my cache was implemented with redis clustering (cluster by server not client). I have to flush redis every time I run a unit test. when I try to run flushdb command I got this error: Cannot use 'FLUSHDB' with redis-cluster. it seems that I can run flushdb command in cluster mode only when I set the slot but I do not know how to do it. (I have overridden redis wrapper of laravel so laravel is not the case If you learn me how to use predis I can adopt it with laravel)

like image 391
Mohammad Reza Esmaeilzadeh Avatar asked Jun 29 '15 11:06

Mohammad Reza Esmaeilzadeh


People also ask

How do I flush all Redis?

To clear data of a DCS Redis 4.0 or 5.0 instance, you can run the FLUSHDB or FLUSHALL command in redis-cli, use the data clearing function on the DCS console, or run the FLUSHDB command on Web CLI. To clear data of a Redis Cluster instance, run the FLUSHDB or FLUSHALL command on every shard of the instance.

How do I clear Redis cache in Kubernetes?

The easiest way to clear Redis cache is to use the redis-cli command. Databases in Redis are stored individually. Using the redis-cli command allows you to either clear the keys from all databases, or from a single specified database only.

How do I flush Redis cache in AWS?

What is the command to delete all keys from my redis cluster? FLUSHDB command – Delete all the keys of the currently selected DB. FLUSHALL command – Remove all the keys of all the existing databases, not just the currently selected one.

What is Redis Sharding?

A shard (in the API and CLI, a node group) is a hierarchical arrangement of nodes, each wrapped in a cluster. Shards support replication. Within a shard, one node functions as the read/write primary node. All the other nodes in a shard function as read-only replicas of the primary node.


1 Answers

For deleting by pattern:

redis-cli --raw keys "$PATTERN" | xargs redis-cli del

for example:

redis-cli KEYS "prefix:*" | xargs redis-cli DEL

For deleting all keys from one db:

redis-cli flushdb

For deleting all keys from all dbs:

redis-cli flushall

For cluster mode you need to use this bash script: https://gist.github.com/yaud/85e0382d26c189bdf84f0297cd54f479 to remove all nodes from master nodes (slave nodes will be synced)

like image 197
Mohammad Reza Esmaeilzadeh Avatar answered Oct 20 '22 22:10

Mohammad Reza Esmaeilzadeh