标签:col 失败 redis命令 false ant code 分享图片 end com
pipeline管道可以减少后端与redis的连接次数,从而实现了优化。
未使用pipeline前:
strict_redis = get_redis_connection(‘sms_codes‘) # type:StrictRedis strict_redis.setex(‘sms_%s‘ % mobile,constants.SMS_CODE_REDIS_EXPIRES, sms_codes) strict_redis.setex(‘send_flag_%s‘ % mobile,constants.SEND_SMS_CODE_INTERVAL, 1)
使用pipeline后:
strict_redis = get_redis_connection(‘sms_codes‘) # type:StrictRedis pipeline = strict_redis.pipeline() # type:pipeline pipeline.setex(‘sms_%s‘ % mobile,constants.SMS_CODE_REDIS_EXPIRES, sms_codes) pipeline.setex(‘send_flag_%s‘ % mobile,constants.SEND_SMS_CODE_INTERVAL, 1) pipeline.execute()
拓展:
pipline.execute()有返回值,是一个列表,返回值的True或False,代表执行成功或失败
标签:col 失败 redis命令 false ant code 分享图片 end com
原文地址:https://www.cnblogs.com/chichung/p/9957399.html