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
相关文章
- Redis 简介以及安装介绍
- 【Redis】yum安装redis
- 解决方法:配置群集时# gem install redis 报错:Unable to require openssl, install OpenSSL and rebuild ruby
- Python操作 RabbitMQ、Redis、Memcache、SQLAlchemy
- Redis学习(5)-Jedis(Java操作redis数据库技术)
- spring boot:用redis+lua实现基于ip地址的分布式流量限制(限流/简单计数器算法)(spring boot 2.2.0)
- Redis-Cluster实战--5.使用redis-cli安装
- Redis两种方式实现限流
- thinkphp6:根据ip和时间用redis做限流(thinkphp v6.0.12LTS)
- thinkphp6:访问多个redis数据源(thinkphp6.0.5 / php 7.4.9)
- Redis 集群方案
- Spring Data Redis 让 NoSQL 快如闪电 (1)
- 〖Python 数据库开发实战 - Python与Redis交互篇④〗- 利用 redis-py 实现集合与有序集合的常用指令操作
- HBase vs Redis
- Redis的那些事儿:关系型和非关系型数据库,非关系型数据库的类型,redis数据类型、编码格式、高性能、可以做什么、分布式锁失效的原因,string为采用sds数据类型,为什么是二进制安全的,
- 库存秒杀问题-redis解决方案- 接口限流
- Centos7 安装PHP7版本及php-fpm,redis ,php-redis,hiredis,swoole 扩展安装
- 012-redis应用-05-限流【简单限流、漏斗限流】
- 【服务器安装Redis】Centos7离线安装redis
- springboot+jwt+shiro+vue+elementUI+axios+redis+mysql简易博客项目
- 【C++ 科学计算】redis-plus-plus:安装用C ++编写的Redis客户端
- Redis is configured to save RDB snapshots redis的 rdb持久化错误
- Redis Hash哈希类型字符串(五)