Skip to content

Instantly share code, notes, and snippets.

@0x2a94b5
Last active October 12, 2021 03:34
Show Gist options
  • Save 0x2a94b5/09062327ff9812ad22b747cd1754ecca to your computer and use it in GitHub Desktop.
Save 0x2a94b5/09062327ff9812ad22b747cd1754ecca to your computer and use it in GitHub Desktop.
"""
python redis basic operations
---
sudo apt install redis
pip install redis
"""
from redis import Redis
r = Redis(host='127.0.0.1', port=6379, charset='utf-8', decode_responses=True)
def set_redis(key, value, expire_time):
return r.set(key, value, ex=expire_time)
def get_redis(key):
return r.get(key)
if __name__ == '__main__':
result = set_redis('name', 'python', 120)
name = get_redis('name')
print(f'The return value is {result}.\nThe value obtained is {name}.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment