Skip to content

Commit

Permalink
Add LMOVE command
Browse files Browse the repository at this point in the history
  • Loading branch information
marocchino committed Mar 8, 2024
1 parent f9259a6 commit ddcc4b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/redis/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Namespace
"lindex" => [ :first ],
"linsert" => [ :first ],
"llen" => [ :first ],
"lmove" => [ :first_two ],
"lpop" => [ :first ],
"lpos" => [ :first ],
"lpush" => [ :first ],
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit ddcc4b9

Please sign in to comment.