skip to Main Content

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?

2

Answers


  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
    
    Login or Signup to reply.
  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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search