Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LMPOP not working #1237

Closed
CoderMiguel opened this issue Nov 16, 2023 · 5 comments
Closed

LMPOP not working #1237

CoderMiguel opened this issue Nov 16, 2023 · 5 comments

Comments

@CoderMiguel
Copy link

I am working with Redis to build some queues and would like to have a primary and secondary queue / lists. LMPOP feels like the right method to be using to get values from the primary list first and the secondary only providing values when the primary list is exhausted.

If I build 2 lists as follows:

redis = Redis.new
redis.rpush(:numbers, [*1..5])
redis.rpush(:letters, [*'a'..'e'])

I am able to verify that they have been populated:

redis.lrange(:numbers, 0, -1) # => ["1", "2", "3", "4", "5"]
redis.lrange(:letters, 0, -1) # => ["a", "b", "c", "d", "e"]

I expect to get '1' if I were to lmpop from these lists as follows:

redis.lmpop(:numbers, :letters)

Instead I get the following error:

Redis::CommandError: ERR unknown command `lmpop`, with args beginning with: `2`, `numbers`, `letters`, `LEFT`, 
from /usr/local/bundle/gems/redis-client-0.18.0/lib/redis_client/connection_mixin.rb:35:in `call'
Caused by RedisClient::CommandError: ERR unknown command `lmpop`, with args beginning with: `2`, `numbers`, `letters`, `LEFT`, 
from /usr/local/bundle/gems/redis-client-0.18.0/lib/redis_client/connection_mixin.rb:35:in `call'

I am using:
Using rails 7.0.7.2
Using redis 5.0.8
Using redis-client 0.18.0

I was able to find this open issue: #1187
but it appears that the code for LMPOP and BLMPOP have both been merged and are in the version of the gem that I am using:

def lmpop(*keys, modifier: "LEFT", count: nil)

So it feels like these methods should be accessible and working, but maybe they are still in development and we would need to find a workaround until they are finished?

@CoderMiguel
Copy link
Author

Possible workaround:

redis.lpop(:numbers) || redis.lpop(:letters)

@byroot
Copy link
Collaborator

byroot commented Nov 16, 2023

What's your redis server version?

You can check it with redis.info["redis_version"]

@CoderMiguel
Copy link
Author

redis.info["redis_version"] # => "6.2.6"

@byroot
Copy link
Collaborator

byroot commented Nov 16, 2023

LMPOP was added in 7.0, your Redis server is too old: https://redis.io/commands/lmpop/

@byroot byroot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 16, 2023
@CoderMiguel
Copy link
Author

Thanks for pointing me to the problem, I was able to update the Redis server and this started working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants