-
-
Save swdevbali/4784eda924affad5d3cf to your computer and use it in GitHub Desktop.
__author__ = 'ekowibowo' | |
import json | |
import os | |
import redis | |
REDIS_HOST = os.getenv('SS_ABTEST_REDIS_HOST', '192.168.59.103') | |
r = redis.StrictRedis(host=REDIS_HOST) | |
for k in r.keys('abtest:experiments:*'): | |
r.delete(k) | |
exp1 = { | |
"id": 1, | |
"name": "testExperiment", | |
"device": "desktop", | |
"active": False, | |
"buckets": [ | |
{ | |
"name": "bucket1" | |
}, | |
{ | |
"name": "bucket2" | |
} | |
] | |
} | |
exp1_json_dumps = json.dumps(exp1) | |
print 'json.dumps:', exp1_json_dumps, ' type=', type(exp1_json_dumps) | |
r.set('abtest:experiments:1', exp1_json_dumps) | |
exp1_from_redis = r.get('abtest:experiments:1') | |
print 'exp1_from_redis', exp1_from_redis, ' type=', type(exp1_from_redis) | |
exp1_from_redis_json_loads = json.loads(exp1_json_dumps) | |
print 'exp1_from_redis_json_loads', exp1_from_redis_json_loads, 'type=', type(exp1_from_redis_json_loads) |
YOUR WROOOOONG!!!!
Sorry, @swdevbali if this was too rush but, isn't what you say are going to do.
I've found this because is the first Google's suggestion.
And guess what! You never load the redis get.
Your just reloading the same json dump, not the redis one.
json.loads(exp1_json_dumps)
you should use
json.loads(exp1_from_redis)
This is your code:
exp1_json_dumps = json.dumps(exp1)
print 'json.dumps:', exp1_json_dumps, ' type=', type(exp1_json_dumps)
r.set('abtest:experiments:1', exp1_json_dumps)
exp1_from_redis = r.get('abtest:experiments:1')
print 'exp1_from_redis', exp1_from_redis, ' type=', type(exp1_from_redis)
exp1_from_redis_json_loads = json.loads(exp1_json_dumps)
But, flash news! It won't work!
Anyway, I'm still stuck at this and will continue with my research.
`json.dumps: {"device": "desktop", "active": false, "buckets": [{"name": "bucket1"}, {"name": "bucket2"}], "id": 1, "name": "testExperiment"} type= <type 'str'>
exp1_from_redis {"device": "desktop", "active": false, "buckets": [{"name": "bucket1"}, {"name": "bucket2"}], "id": 1, "name": "testExperiment"} type= <type 'str'>
exp1_from_redis_json_loads {u'device': u'desktop', u'active': False, u'buckets': [{u'name': u'bucket1'}, {u'name': u'bucket2'}], u'id': 1, u'name': u'testExperiment'} type= <type 'dict'>`