使用redis-py库建立redis访问连接可以有Redis, StrictRedis两种方式,两种模式下的函数参数顺序有所不同.StrictRedis模式函数参数顺序与redis-cli命令相同.
经常用到的命令SETEX key seconds value的两种python调用方式
- Redis方式
import redis as redis_py
redis = redis_py.Redis(host='localhost', port=6379, db=0)
redis.setex(key, value, seconds)
- StrictRedis方式
import redis as redis_py
redis = redis.StrictRedis(host='localhost', port=6379, db=0)
redis.setex(key, seconds, value)
在StrictRedis方式下以redis.setex(key, value, seconds)方式调用, 在Redis方式下以redis.setex(key, seconds, value)方式调用,将返回错误value is not an integer or out of range.

本文介绍了如何使用Python的redis-py库通过Redis和StrictRedis两种模式调用SETEX命令。详细对比了两种模式下的参数顺序差异,并提供了具体的代码示例。
980

被折叠的 条评论
为什么被折叠?



