keys * 查看所有的值
flushdb 刷新(清空)
set "mobile" "18888888888"
get "mobile"

首先启动redis-server.exe,然后启动redis-cli.exe

1
2
3
4
5
6
7
8
9
import time
import redis

r = redis.Redis(host="127.0.0.1", port=6379, db=0, charset="utf8", decode_responses=True)# 设置编码

r.set('foo', "test")
r.expire("foo", 1)# 设置过期时间1秒钟
time.sleep(1)
print(r.get("foo"))