In redis, how do i remove keys?

2019-01-21 21:21发布

I want to remove keys that match "user*".

how do I do that in redis command line?

8条回答
forever°为你锁心
2楼-- · 2019-01-21 22:13

When using the oneliner, you can edit the pattern in case it escapes specific characters. For instance, to delete patterns like '\b test \b' use:

redis-cli --raw KEYS '\\b*' | sed 's/\\b/\\\\b/g' | xargs redis-cli del
查看更多
\"骚年 ilove
3楼-- · 2019-01-21 22:15

Using awk, find all matching keys from redis using redis-cli KEYS command and pipe to redis-cli DEL command.

redis-cli KEYS "user*"  | awk '{ system("redis-cli DEL " $1) }'
查看更多
登录 后发表回答