Skip to content

Deprecation warning from Redis::List#shift #269

@eguchi-ken

Description

@eguchi-ken

problem

I used Redis::List#shift

list = Redis::List.new("test")
list.push(10)
list.push(20)

list.shift(1)

list.shift(1) is working. However, it printed following message.

Pipelining commands on a Redis instance is deprecated and will be removed in Redis 5.0.0.

redis.multi do
  redis.get("key")
end

should be replaced by

redis.multi do |pipeline|
  pipeline.get("key")
end

(called from ~/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/redis-objects-1.7.0/lib/redis/objects/connection_pool_proxy.rb:10:in `block in method_missing'}

solution

I think that following code should use pipleline instead of redis.

def shift(n=nil)
if n
result, = redis.multi do
redis.lrange(key, 0, n - 1)
redis.ltrim(key, n, -1)
end
unmarshal result
else
unmarshal redis.lpop(key)
end
end

I'll probably fix it like this.

        result, = redis.multi do |pipeline|
          pipeline.lrange(key, 0, n - 1)
          pipeline.ltrim(key, n, -1)
        end

Could you please fix it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions