-
-
Save aj07mm/8b973874d47cd96042273c822c44697e to your computer and use it in GitHub Desktop.
Simply json.dumps() => save to redis => redis.get => json.loads() => Python dict with proper data type created
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment