From ddcc4b97abfc5c338ee16e0770535d53e921b92b Mon Sep 17 00:00:00 2001 From: marocchino Date: Fri, 8 Mar 2024 17:02:37 +0900 Subject: [PATCH] Add LMOVE command --- lib/redis/namespace.rb | 5 +++++ spec/redis_spec.rb | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/redis/namespace.rb b/lib/redis/namespace.rb index 6c44e21..517d9cc 100644 --- a/lib/redis/namespace.rb +++ b/lib/redis/namespace.rb @@ -103,6 +103,7 @@ class Namespace "lindex" => [ :first ], "linsert" => [ :first ], "llen" => [ :first ], + "lmove" => [ :first_two ], "lpop" => [ :first ], "lpos" => [ :first ], "lpush" => [ :first ], @@ -457,6 +458,10 @@ def call_with_namespace(command, *args, &block) when :first args[0] = add_namespace(args[0]) if args[0] args[-1] = ruby2_keywords_hash(args[-1]) if args[-1].is_a?(Hash) + when :first_two + args[0] = add_namespace(args[0]) if args[0] + args[1] = add_namespace(args[1]) if args[1] + args[-1] = ruby2_keywords_hash(args[-1]) if args[-1].is_a?(Hash) when :all args = add_namespace(args) when :exclude_first diff --git a/spec/redis_spec.rb b/spec/redis_spec.rb index 8c9df07..db7e6c3 100644 --- a/spec/redis_spec.rb +++ b/spec/redis_spec.rb @@ -106,6 +106,14 @@ expect(@redis.lpos('mykey', 'c')).to be_nil end + it 'should be able to use a namespace with lmove' do + @namespaced.rpush('foo', %w[a b c 1 2 3 c c]) + expect(@namespaced.lmove('foo', 'bar', 'LEFT', 'RIGHT')).to eq('a') + expect(@namespaced.lmove('foo', 'bar', 'LEFT', 'RIGHT')).to eq('b') + expect(@namespaced.lrange('foo', 0, -1)).to eq(%w[c 1 2 3 c c]) + expect(@namespaced.lrange('bar', 0, -1)).to eq(%w[a b]) + end + it 'should be able to use a namespace with brpoplpush' do @namespaced.lpush('foo','bar') expect(@namespaced.brpoplpush('foo','bar',0)).to eq('bar')