Lionel Dcosta
Lionel Dcosta

Reputation: 176

How to delete all the cache using predis in php

I am using predis library to cache the data. I am able to delete the cache individually using

$redis->cache->hdel(self::$cacheNamespace, $key);

But i need to delete all the cache without providing any keys, Is there a way to achieve that in predis.

Upvotes: 3

Views: 14744

Answers (4)

hakki
hakki

Reputation: 6519

There two flush functions. One of them for all Redis databases, another is only for specific Redis db. Use them like;

flushAll()

Description: Remove all keys from all databases.

Parameters async (bool) requires server version 4.0.0 or greater

Return value BOOL: Always TRUE.

Example

$redis->flushAll();

flushDb()

Description: Remove all keys from the current database.

Parameters async (bool) requires server version 4.0.0 or greater

Return value BOOL: Always TRUE.

Example

$redis->flushDb();

Source: https://github.com/phpredis/phpredis#flushdb

Upvotes: 0

Amitesh Bharti
Amitesh Bharti

Reputation: 15775

PHP Method Predis\Client::flushAll Code Examples

predis equivalent of redis-cli FLUSHALL

public function flushAll()
{
    $this->_redis->flushAll();
}
  • Removes data from ALL databases.

Upvotes: 2

gaalgergely
gaalgergely

Reputation: 113

Try this: $redis->flushAll();

Upvotes: 4

Noman
Noman

Reputation: 1487

With Cache Clear All, Here you go:

cache_clear_all();

For my point of view, You have to use redis cli:

redis-cli flushall

For more info FlushAll.

Upvotes: 5

Related Questions