Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanermita/d26bd0e0b5658fa8811981d508696f99 to your computer and use it in GitHub Desktop.
Save ryanermita/d26bd0e0b5658fa8811981d508696f99 to your computer and use it in GitHub Desktop.
dict_object = {
"name": "John Doe",
"social_media_accounts": ["facebook", "twitter", "Instagram"],
"language_proficiency": {
"Python": "9/10",
"Javascript": "7/10",
"Ruby": "8/10"
}
}
# convert your dict object to string
stringified_dict_obj = json.dumps(dict_object)
type(stringified_dict_obj) # str
# cache stringified dict_object
app.redis_connection.set("your_unique_key", stringified_dict_obj)
# fetch cached data (string) from redis
cached_data = app.redis_connection.get("your_unique_key")
type(cached_data) # str
# convert your string cached data to object(dict/JSON)
cached_data_as_dict = json.loads(cached_data)
type(cached_data_as_dict) # dict
type(cached_data_as_dict["social_media_accounts"]) # list
type(cached_data_as_dict["language_proficiency"]) # dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment