python - How do I use redis to cache HTTP Response objects -
i trying utilize redis caching backend http responses. problem modelling response object redis. in document store, info this:
def set_data(response): data= { '_id': key, 'time': time(), 'status': response.status, 'url': response.url, 'headers': dict(response.headers), 'body': headers.body } my problem lies in field 'headers' dict. in redis, can nest hash info construction use-case? design practices model complex fields in redis? should store headers different key? like:
headers_key= some_prefix+key and utilize redis hash info construction store headers dict? or should serialize headers?
what should doing? have looked various ways can it, cant figure out optimal way. need enlightenment on best practices used utilize case in redis. please help.thank you.
you can utilize json serialize , de-serialize dict. string object redis store. like:
import json headers = json.dumps(dict(response.headers)) # store redis headers_dict = json.loads(headers) # it's dict 1 time again python redis
No comments:
Post a Comment