Created
October 16, 2019 14:48
-
-
Save RomanSteinberg/37849c64263965cc26bda1582c158cdb to your computer and use it in GitHub Desktop.
redis json sample code
This file contains hidden or 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
import redis | |
import json | |
data = { | |
'foo': 'bar', | |
'd': {'a': 1} | |
} | |
r = redis.StrictRedis() | |
r.execute_command('JSON.SET', 'doc', '.', json.dumps(data)) | |
reply = json.loads(r.execute_command('JSON.GET', 'doc')) | |
print(reply) | |
r.execute_command('JSON.DEL', 'doc', '.d') | |
reply = json.loads(r.execute_command('JSON.GET', 'doc')) | |
print(type(reply)) | |
# reply = [json.loads(elem) for elem in r.execute_command('JSON.OBJKEYS', 'doc', '.')] | |
reply = r.execute_command('JSON.OBJKEYS', 'doc', '.') | |
for elem in reply: | |
print(elem.decode('utf-8')) | |
print(f'{elem}') | |
print(type(reply[0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment