9951 explained code solutions for 126 technologies


python-redisGet JSON from Redis


r = redis.Redis()
obj = json.loads(r.get('d2'))ctrl + c
redis.Redis

connect to Redis server

'd2'

name of the key to get our JSON from (assume JSON string is stored there already)

json.loads

converts JSON string to dict object

obj =

variable will store resulting dict object


Usage example

import redis, json

obj = {'name': 'Donald', 'years': [4, 8, 12]}

r = redis.Redis()
r.set('d2', json.dumps(obj))

res = json.loads(r.get('d2'))
print(res)
output
{'name': 'Donald', 'years': [4, 8, 12]}