Last active
October 12, 2021 03:34
-
-
Save 0x2a94b5/09062327ff9812ad22b747cd1754ecca to your computer and use it in GitHub Desktop.
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
""" | |
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