forked from sds/mock_redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipelined_spec.rb
114 lines (91 loc) · 2.45 KB
/
pipelined_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
require 'spec_helper'
describe '#pipelined' do
it 'yields to its block' do
res = false
@redises.pipelined do
res = true
end
res.should == true
end
context 'with a few added data' 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.get key1
redis.get key2
end
results.should == [value1, value2]
end
it 'returns futures' do
future = nil
@redises.mock.pipelined do |redis|
future = redis.get key1
end
future.class.should be MockRedis::Future
end
end
context 'with pipelined operations returning array replies' do
let(:key1) { 'colors' }
let(:key2) { 'seasons' }
let(:value1) { %w[blue yellow] }
let(:value2) { %w[summer winter] }
before do
@redises.rpush(key1, value1)
@redises.rpush(key2, value2)
end
after do
@redises.del key1
@redises.del key2
end
it 'returns an array of the array replies' do
results = @redises.pipelined do |_redis|
@redises.lrange(key1, 0, -1)
@redises.lrange(key2, 0, -1)
end
results.should == [value1, value2]
end
end
context 'with redis time return value' do
let(:time_stub) { double 'Time', :now => Time.new(2019, 1, 2, 3, 4, 6, '+00:00') }
let(:options) { { :time_class => time_stub } }
subject { MockRedis.new(options) }
it 'returns the time value' do
subject.set('foo', 'bar')
results = subject.pipelined do
subject.get('foo')
subject.host # defined on MockRedis, so not captured
subject.time
subject.echo('baz')
end
expect(results).to eq(['bar', [1_546_398_246, 0], 'baz'])
end
end
context 'with nested pipelines' 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 the nested pipelines' do
results = @redises.pipelined do |pr1|
pr1.pipelined do |pr2|
pr2.get key1
end
pr1.pipelined do |pr2|
pr2.get key2
end
end
results.should == [value1, value2]
end
end
end