5

I was able to flash all keys from terminal using redis-cli flushdb. I have been searching for a while, took me an hour in order to find the simple command to do it in php.

I didn't find it on stackoverflow so I wanted to post it to save someone precious time.

Library Used: Predis

Onix
  • 2,129
  • 2
  • 17
  • 26

1 Answers1

9

If you have the redis connection you can simply do $redis->flushDB(); to delete all keys from the selected database.

Or if you are using laravel framework you could also do Redis::flushDB();

Onix
  • 2,129
  • 2
  • 17
  • 26
  • 3
    Laravel also allows you to use `\Cache::store("redis")->flush()` – apokryfos Nov 06 '17 at 10:28
  • yes that one works too. but it deletes the current db keys or all ? – Onix Nov 06 '17 at 10:30
  • If the underlying CacheStore is `RedisStore` it just calls flushDB. The advantage is though that if you have code line `\Cache::flush()` then it will keep working when you switch from redis to something else. – apokryfos Nov 06 '17 at 10:34