zoukankan      html  css  js  c++  java
  • Redis 漏斗限流 (redis-cell)

    上述的漏斗限流算法,在Redis的模块中已经内置实现了一个,具体介绍请参见Github redis-cell详细介绍 笔者安装在MacOS上,基本没有问题:

    # 下载mac版本安装包
    https://github.com/brandur/redis-cell/releases
    # 解压
    tar -zxf redis-cell-*.tar.gz
    # 复制可执行文件
    cp libredis_cell.dylib /your_redis_server_localtion
    # 重启redis-server,把libredis_cell.dylib加载上
    redis-server --loadmodule /path/to/modules/libredis_cell.dylib
    1
    2
    3
    4
    5
    6
    7
    8
    安装重启后,可以在redis中执行 CL.THROTTLE 命令:

    # CL.THROTTLE user123 15 30 60 1和实现算法中的配置类似,user123表示限流key,15: capacity,30: total,60: duration,
    127.0.0.1:6379> CL.THROTTLE user123 15 30 60 1
    1) (integer) 0 # 0表示允许,1表示拒绝
    2) (integer) 16 # 漏斗容量 max_burst + 1 = 15 +1 =16
    3) (integer) 15 # 漏斗剩余容量
    4) (integer) -1 # 如果被拒绝,多少秒后重试
    5) (integer) 2 # 多长时间后漏斗完全漏空
    1
    2
    3
    4
    5
    6
    7
    但是redis-cell没有找到对应的sdk

    Python Bound method
    # python 3.x
    def func():
    pass

    class A:
    @classmethod
    def method_cls(cls):
    pass
    def method_a(self):
    pass
    class B(A):
    pass

    a, b = A(), B()
    print(func) # <function func at 0x10ee8a1e0>
    print(a.method_a) # <bound method A.method_a of <__main__.A object at 0x10ef11978>>
    print(b.method_cls) # <bound method A.method_cls of <class '__main__.B'>>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    对于上文中 func就是一个函数对象,而method_a 和 method_cls 是归属类A的所以,是一个bound method,那么如何查看一个 bound method的归属呢?
    Python 2.x中提供了 im_func,im_class,im_self三个属性:

    im_func is the function object.
    im_class is the class the method comes from.
    im_self is the self object the method is bound to.
    Python3.x中

    __func__ replace im_func
    __self__ replace im_self
    2.x中的 im_class取消
    # python 3.x
    print(a.method_a.__self__)
    print(b.method_cls.__self__)
    # print(func.__self__) error func 无 __self__
    print(b.method_cls.__self__.__name__)
    # print(b.method_cls.__self__.__name__) error b.method_cls.__self__是一个实例,无__name__属性
    1
    2
    3
    4
    5
    6
    关于 __name__ 和 __qualname__ 请参见 PEP 3155
    ————————————————
    版权声明:本文为CSDN博主「Inevitable-Neo」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/duxiangwushirenfei/article/details/99982959

  • 相关阅读:
    【设置图片主体部分居中】
    高效数据查询设计思想
    SpringBoot中的classpath
    mysql优化口诀
    windows安装kafka
    windows安装rabbitmq
    使用Charles在移动端抓包
    07 哨兵机制:主库挂了,如何不间断服务
    操作系统(一)操作系统历史:从标准函数库到云计算
    06 数据同步:主从库如何实现数据一致
  • 原文地址:https://www.cnblogs.com/ExMan/p/12084923.html
Copyright © 2011-2022 走看看