正文
python 使用 redis expire属性设置访问时间间隔
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
安装redis
yum install redis
安装python redis扩展
pip install redis
启动redis,并设定开机自动启动
service redis start
chkconfig redis on
安装完成,然后开始编码,然后存储键值foo,并设置过期时间是60S。
import redis
pool=redis.ConnectionPool(host='localhost',port=,db=)
r = redis.StrictRedis(connection_pool=pool)
r.set('foo', 'Bar')
r.expire('foo', )
然后去请求变量:
>>> r.exists('foo')
False
完毕。