Managing redis keys using wildcards in Cakephp

时间:2016-05-17 11:09:09

标签: cakephp redis

I use cakephp 2 and redis.

How do I remove all keys from cache by the wildcards mask? For example I want to remove all by mask "prefix_element_group1*"

About clearGroup I know. But it only increments the group value to simulate deletion of all keys under a group old values will remain in storage until they expire.

At least how to get a list of keys using a mask? similar to "keys *" in redis-cli

1 个答案:

答案 0 :(得分:0)

您的问题并非特定于CakePHP。您可以使用带有eval的Lua脚本删除带有通配符支持的任意键。这是一个PHP示例:

$deleteScript = 'return redis.call("DEL", unpack(redis.call("keys", ARGV[1])))';
$redis = getRedisConnection(); // whatever CakePHP provides
$redis->eval($deleteScript, 0, "keyPattern:*");

显然,确切的语法会因您的特定Redis库而有所不同,但希望这可以为您提供正确的想法。