0

I'm trying to use zpopmax with a sorted set in python rediscluster (repo), but the very simple program below fails with AttributeError.

Question: How can I implement zpopmax with rediscluster? If it's really not implemented, I'll have to use both zrevrange and zrem in a transaction to ensure thread safety.

Possibly useful background

I've noticed the command is available in regular (not clustered) redis-py. I also see the command tested in the git repo so I may be missing something easy.

I also tried zpopmax using regular redis and get the same error.

My reids-py-cluster is v1.3.6. My redis-py is v2.10.6. My actual Redis is v5.0.4

Code

    from rediscluster import StrictRedisCluster as s

    rc = s(startup_nodes=[{'host': 'localhost', 'port': '7000'}],
           decode_responses=True)
    rc.zadd('my-set-name', 3, 'my-key-name')

    # print to confirm zadd worked
    print(rc.zrange('my-set-name', 0, -1, withscores=True)) 

    # expecting this to print 'my-key-name'
    print(rc.zpopmax('my-set-name')) # Attribute Error

I expect the output of the last print statement to be something like 'my-key-name` but I'm getting an AttributeError

Thanks for the help :)

Dan Pittsley
  • 143
  • 7

2 Answers2

0

The issue appears to be that redis-py added support for ZPOPMAX in version 3.0, but redis-py-cluster 1.3.6 requires an older version of redis-py.

The easiest solution here is probably just to wait for redis-py-cluster to be updated. The problems caused by this pinning have been acknowledged, and the next version will add support for redis-py 3.0.

Kevin Christopher Henry
  • 46,175
  • 7
  • 116
  • 102
  • Thanks for the help. Can you help me understand how 1) [redis-py-cluster](https://github.com/Grokzen/redis-py-cluster), 2) [redis-py](https://github.com/andymccurdy/redis-py) and 3) [actual Redis](https://redis.io/) work together? For those three, I have versions v1.3.6, v2.10.6, and v5.0.4 respectively. So I _think_ if any versions are wrong, it wouldn't be "actual Redis". I'll edit to add that info in my question. – Dan Pittsley Sep 03 '19 at 14:33
  • @DanPittsley: You're welcome. I've updated the answer based on the new information. – Kevin Christopher Henry Sep 03 '19 at 15:24
  • Got it. Based on the great info you provided, I *was* actually able to get `zpopmax()` working by updating my versions. I need redis-py-cluser v2.0.0 and redis v3.0.1 – Dan Pittsley Sep 03 '19 at 16:37
0

Versions! As documented in Kevin's answer, versions are the issue here. However, I can actually get things working with this setup:

Code

from rediscluster import RedisCluster as s

rc = s(startup_nodes=[{'host': 'localhost', 'port': '7000'}],
       decode_responses=True)
rc.zadd('my-set-name', {'my-key-name':3})

print(rc.zpopmax('my-set-name')) # WORKS! (prints [('my-key-name', 3.0)])

Thanks to Kevin Christopher Henry for help getting there.

Dan Pittsley
  • 143
  • 7