I am using redis-py (https://redis-py.readthedocs.org/en/latest/).
lets say I have some redis keys saved and av. 'av' has no assigned value so using the command line, I can do:
>>> redis.get('saved')
Out[4]: 'None'
>>> redis.get('av')
>>> redis.get('saved')
Out[6]: 'None'
How would you test for 'no assigned value' for a key in this context?
You should use the method exists
, which returns a boolean - True
if your key is set, False
otherwise. You should avoid the use of get
for that, as it can raise an exception if you have a list value for that key.
Example:
>>> redis.exists("av")
False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With