使用 redis-py-cloud 操作 redis5 stream 数据 - V2EX
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
copyangle

使用 redis-py-cloud 操作 redis5 stream 数据

  •  
  •   copyangle Apr 4, 2019 1997 views
    This topic created in 2599 days ago, the information mentioned may be changed or developed.

    redis-py-cloud 是基于 redis-py-cluster 开发的 redis 集群包,特别支持 redis5.0 的 stream 新特性。目前支持的命令有xadd, xread, xreadgroup, xack 等。

    包下载地址:

    https://github.com/ChinaGoldBear/redis-py-cloud

    或 pip install:

    pip install redis-py-cloud

    基本操作:

    1.连接集群

    from rediscluster import RedisCluster

    '''连接集群''' startup_nodes = [{"host": "ip3", "port": "7000"}, {"host": "ip2", "port": "7000"}, {"host": "ip1", "port": "7000"}, ]

    REDIS_CLUSTER = RedisCluster(startup_nodes=startup_nodes, decode_respOnses=True)

    2.xadd

    REDIS_CLUSTER.xadd("mystream", "*", 100,{"name": "data"})

    3.xread

    REDIS_CLUSTER.xread("mystream","*",1) # 非阻塞读取最后一条

    REDIS_CLUSTER.xread("mystream","*",1,0) # 阻塞读取最后一条

    REDIS_CLUSTER.xread("mystream","*",10,0)# 阻塞读取最后 10 条

    REDIS_CLUSTER.xread("mystream","1527849629172-0",1,0) # 阻塞读取特定消息

    1. xrange

    REDIS_CLUSTER.xrange("mystream","-","+") # -表示最小值, +表示最大值

    REDIS_CLUSTER.xrange("mystream","1527849629172-0","+") # 指定最小消息 ID 的列表

    REDIS_CLUSTER.xrange("mystream","-","1527849629172-0") # 指定最大消息 ID 的列表

    5.xreadgroup

    REDIS_CLUSTER.xreadgroup("group_name","consumer_name","mystream",">",0) # 消息组读取,0 表示阻塞读取

    REDIS_CLUSTER.xreadgroup("group_name","consumer_name","mystream",">") # 消息组读取,非阻塞读取

    REDIS_CLUSTER.xreadgroup("group_name","consumer_name","mystream","1527849629172-0") # 消息组特定消息读取,非阻塞读取

    6.xack

    REDIS_CLUSTER.xack("mystream","counsumer_name","1527849629172-0") # ack 消费组消息

    其他 stream 命令请参考:

    https://blog.csdn.net/enmotech/article/details/81230531

    作者:copyangle 来源:CSDN 原文: https://blog.csdn.net/copyangle/article/details/81975975 版权声明:本文为博主原创文章,转载请附上博文链接!

    No Comments Yet
    About     Help     Advertise     Blog     API     FAQ     Solana     890 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 20:39 PVG 04:39 LAX 13:39 JFK 16:39
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86