0

How to remove all elements in Redis? I tried with the following snippet code from this post but didn't work.

I've such this:

import redis
from pprint import pprint

cli = redis.Redis('localhost')

dict_ = {  # dummy
    'tags': {'module': 'voltage', 'station': 'SNMP'},
    'metric_name': 'voltage',
    'value': 222,
    'time': '2018-11-13T15:25:09'
}
cli.hmset("pythonDict", dict_)

for key in cli.keys('prefix:*'):  # Didn't work.
    cli.delete(key)

pprint(cli.hgetall("pythonDict"))

Still, the previous data appeared from dict_.

Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150

1 Answers1

1

You're storing in Redis an object (dict_) under the key called 'pythonDict'. Just call cli.delete("pythonDict") to delete it.

Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
Itamar Haber
  • 47,336
  • 7
  • 91
  • 117