Physics Derivation Graph navigation
Sign in
notes on learning redis
Published 2020-04-08T22:16:00.002Z by Physics Derivation Graph
I'm running redis in a docker container and connecting to it from Python using
https://github.com/andymccurdy/redis-py
>>> from redis import Redis
I initially wasn't able to connect until I found this
https://stackoverflow.com/a/57681086/1164295
>>> rd.ping()
True
>>> rd = Redis(host='docker.for.mac.localhost', port=6379)
Then I used
https://realpython.com/python-redis/#ten-or-so-minutes-to-redis
What keys exist?
>>> rd.keys()
[b'hits']
Look for a key that doesn't exist:
>>> print(rd.get('mykey'))
None
>>> rd.get('mykey')
>>>
Better method for looking for keys:
>>> rd.exists('mykey')
0
>>> rd.exists('hits')
1