zoukankan      html  css  js  c++  java
  • 使用pipeline管道执行redis命令

    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,代表执行成功或失败

  • 相关阅读:
    SVN 安装 使用指南
    使用angular-cli快速搭建项目命令
    angular 路由的引用
    c#默认类的修饰符。
    c#
    js改变dom对象样式
    jquery常用函数
    PHP 文件上传
    php 表单代码
    Python 条件语句
  • 原文地址:https://www.cnblogs.com/chichung/p/9957399.html
Copyright © 2011-2022 走看看