'How to clear the key in the specified list in Redis?
Redis has the following data:
key value
code1 num1
code2 num2
...
code6000000 num6000000
I have a known fixed list which is not regular:
{code1, code3, code11, ..., code1234567}
How should I design Redis so that I can easily delete these kv?
Solution 1:[1]
Redis has a data structure like hash table this.
you can easily follow instructions there to accomplish your needs.
Example:
redis:6379> HSET myhash field1 "Hello"
(integer) 1
redis:6379> HGET myhash field1
"Hello"
redis:6379> HDEL myhash field1
(integer) 1
Solution 2:[2]
if you want to delete some keys that are stored in a Redis list, you can use this one line shell script in Linux:
> redis-cli LRANGE mylist 0 -1 | xargs redis-cli DEL
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mahdi Yusefi |
| Solution 2 | Shoobi |
