Skip to content

Instantly share code, notes, and snippets.

@lppier
Created January 2, 2019 01:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lppier/7cd007f5fa6af40ef1b22bd236f40f09 to your computer and use it in GitHub Desktop.
Save lppier/7cd007f5fa6af40ef1b22bd236f40f09 to your computer and use it in GitHub Desktop.
Redis Retrieving and Putting a Python Dictionary in Redis
import redis
import json
# Retrieve Redis Stored Values, if any for faster processing
anc_dict_320 = {}
r = redis.Redis(host='localhost', port=6379, db=0)
json_str_320 = r.get("anc_dict_320")
if json_str_320 is not None:
anc_dict_320 = json.loads(json_str_320)
print(anc_dict_320)
# Put data in redis database
if len(anc_dict_320) > 0:
r.set("anc_dict_320", json.dumps(anc_dict_320))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment