PASSWORD RESET

Your destination for complete Tech news

How to retrieve and store a dictionary in Redis?

1.88K 0
< 1 min read

In Redis, you can use the “HMSET” command to store a dictionary as a hash.

For example, if you have a dictionary called “mydict” and want to store it in Redis with the key “mykey”, you can use the following command:

HMSET mykey field1 value1 field2 value2 ...

To retrieve the dictionary from Redis, you can use the “HGETALL” command. For example:

HGETALL mykey

This will return all the fields and values in the hash as a dictionary.

You can also use HMSET and HGETALL in redis-py, which is the python client library for Redis.

import redis
r = redis.Redis(host='localhost', port=6379, db=0)
r.hmset("mykey", {"field1": "value1", "field2": "value2"})
r.hgetall("mykey")

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.