RB3,The redis blaster which support pyton 3.7
rb3的Python项目详细描述
RB3,RB叉支撑python3.7
与getsentry/rb
相比的变化不是兼容性升级。
在这个版本中,rb的这个fork只支持python3.7+(python3.5+已经过测试,但不推荐使用)。
目前,我们关注如何使rb在python3.7下工作,就像它在python2.7上工作一样。
变化crc32
:
现在,我们决定通过编辑rb/router.py
:
classPartitionRouter(BaseRouter):"""A straightforward router that just individually routes commands to single nodes based on a simple ``crc32 % node_count`` setup. This router requires that the hosts are gapless which means that the IDs for N hosts range from 0 to N-1. ``crc32`` returns different value in Python2 and Python3, for details check this link: https://bugs.python.org/issue22341. """def__init__(self,cluster):BaseRouter.__init__(self,cluster)assert_gapless_hosts(self.cluster.hosts)defget_host_for_key(self,key):ifisinstance(key,text_type):k=key.encode('utf-8')else:k=bytes_type(key)# Make sure return value same as in Python3# return (crc32(k) & 0xffffffff) % len(self.cluster.hosts)# Make sure return value same as in Python2crc_res=crc32(k)crc_res=(crc_res-((crc_res&0x80000000)<<1))returncrc_res%len(self.cluster.hosts)
但将来可能会转而使用python 3的本机crc32
函数。
待办事项
- []选择
crc32
方法的选项 - []修复MacOS Travis测试
- []修复pypy travis测试
RB的原始自述文件
RB-Redis爆炸机。
与许多redis节点通信的最快方式。也可以进行路由 盲目地向多个节点发送命令。它是如何工作的?
有关完整文档,请参见rb.rtfd.org
快速启动
设置群集:
fromrbimportClustercluster=Cluster({0:{'port':6379},1:{'port':6380},2:{'port':6381},3:{'port':6382},},host_defaults={'host':'127.0.0.1',})
自动路由:
results=[]withcluster.map()asclient:forkeyinrange(100):client.get(key).then(lambdax:results.append(int(xor0)))print('Sum: %s'%sum(results))
扇出:
withcluster.fanout(hosts=[0,1,2,3])asclient:infos=client.info()
全部扇出:
withcluster.fanout(hosts='all')asclient:client.flushdb()