how can I flush all redis nodes through predis?
Asked Answered
A

1

7

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)

Anschluss answered 29/6, 2015 at 11:23 Comment(0)
A
1

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)

Anschluss answered 26/12, 2018 at 7:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.