Skip to content

Commit

Permalink
Impliment call method in pipelined block
Browse files Browse the repository at this point in the history
  • Loading branch information
ya2k committed Oct 26, 2023
1 parent 36435ec commit c426aec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 0 additions & 4 deletions lib/mock_redis.rb
Expand Up @@ -49,10 +49,6 @@ def id
end
alias location id

def call(command, &_block)
send(*command)
end

def host
options[:host]
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mock_redis/database.rb
Expand Up @@ -43,6 +43,10 @@ def initialize_copy(_source)

# Redis commands go below this line and above 'private'

def call(command, &_block)
public_send(*command)
end

def auth(_)
'OK'
end
Expand Down
22 changes: 22 additions & 0 deletions spec/commands/pipelined_spec.rb
Expand Up @@ -111,4 +111,26 @@
expect(results).to eq([value1, value2])
end
end

context 'with `call` method' do
let(:key1) { 'hello' }
let(:key2) { 'world' }
let(:value1) { 'foo' }
let(:value2) { 'bar' }

before do
@redises.set key1, value1
@redises.set key2, value2
end

it 'returns results of pipelined operations' do
results = @redises.pipelined do |redis|
redis.call(['get', key1])
redis.call(['set', key2, 'foobar'])
redis.call(['get', key2])
end

expect(results).to eq([value1, 'OK', 'foobar'])
end
end
end

0 comments on commit c426aec

Please sign in to comment.