Skip to content

Instantly share code, notes, and snippets.

@RomanSteinberg
Created October 16, 2019 14:48
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 RomanSteinberg/37849c64263965cc26bda1582c158cdb to your computer and use it in GitHub Desktop.
Save RomanSteinberg/37849c64263965cc26bda1582c158cdb to your computer and use it in GitHub Desktop.
redis json sample code
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