rediska 0.0.11 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,136 @@
1
+ shared_examples 'sorted_method' do
2
+ shared_examples_for 'sortable' do
3
+ it 'returns empty array on nil' do
4
+ expect(subject.sort(nil)).to eq([])
5
+ end
6
+
7
+ context 'ordering' do
8
+ it 'orders ascending by default' do
9
+ expect(subject.sort(key)).to eq(['1', '2'])
10
+ end
11
+
12
+ it 'orders by ascending when specified' do
13
+ expect(subject.sort(key, order: 'ASC')).to eq(['1', '2'])
14
+ end
15
+
16
+ it 'orders by descending when specified' do
17
+ expect(subject.sort(key, order: 'DESC')).to eq(['2', '1'])
18
+ end
19
+
20
+ it 'orders by ascending when alpha is specified' do
21
+ expect(subject.sort(key, order: 'ALPHA')).to eq(['1', '2'])
22
+ end
23
+ end
24
+
25
+ context 'projections' do
26
+ it 'projects element when :get is #' do
27
+ expect(subject.sort(key, get: '#')).to eq(['1', '2'])
28
+ end
29
+
30
+ it 'projects through a key pattern' do
31
+ expect(subject.sort(key, get: 'fake-redis-test:values_*')).to eq(['a', 'b'])
32
+ end
33
+
34
+ it 'projects through a key pattern and reflects element' do
35
+ expect(subject.sort(key, get: ['#', 'fake-redis-test:values_*'])).to eq([['1', 'a'], ['2', 'b']])
36
+ end
37
+
38
+ it 'projects through a hash key pattern' do
39
+ expect(subject.sort(key, get: 'fake-redis-test:hash_*->key')).to eq(['x', 'y'])
40
+ end
41
+ end
42
+
43
+ context 'weights' do
44
+ it 'weights by projecting through a key pattern' do
45
+ expect(subject.sort(key, by: 'fake-redis-test:weight_*')).to eq(['2', '1'])
46
+ end
47
+
48
+ it 'weights by projecting through a key pattern and a specific order' do
49
+ expect(subject.sort(key, order: 'DESC', by: 'fake-redis-test:weight_*')).to eq(['1', '2'])
50
+ end
51
+ end
52
+
53
+ context 'limit' do
54
+ it 'only returns requested window in the enumerable' do
55
+ expect(subject.sort(key, limit: [0, 1])).to eq(['1'])
56
+ end
57
+ end
58
+
59
+ context 'store' do
60
+ it 'stores into another key' do
61
+ expect(subject.sort(key, store: 'fake-redis-test:some_bucket')).to eq(2)
62
+ expect(subject.lrange('fake-redis-test:some_bucket', 0, -1)).to eq(['1', '2'])
63
+ end
64
+
65
+ it 'stores into another key with other options specified' do
66
+ expect(subject.sort(key, store: 'fake-redis-test:some_bucket', by: 'fake-redis-test:weight_*')).to eq(2)
67
+ expect(subject.lrange('fake-redis-test:some_bucket', 0, -1)).to eq(['2', '1'])
68
+ end
69
+ end
70
+ end
71
+
72
+ describe '#sort' do
73
+ before(:each) do
74
+ subject.set('fake-redis-test:values_1', 'a')
75
+ subject.set('fake-redis-test:values_2', 'b')
76
+
77
+ subject.set('fake-redis-test:weight_1', '2')
78
+ subject.set('fake-redis-test:weight_2', '1')
79
+
80
+ subject.hset('fake-redis-test:hash_1', 'key', 'x')
81
+ subject.hset('fake-redis-test:hash_2', 'key', 'y')
82
+ end
83
+
84
+ context 'WRONGTYPE Operation' do
85
+ it 'should not allow #sort on Strings' do
86
+ subject.set('key1', 'Hello')
87
+
88
+ expect {
89
+ subject.sort('key1')
90
+ }.to raise_error(Redis::CommandError)
91
+ end
92
+
93
+ it 'should not allow #sort on Hashes' do
94
+ subject.hset('key1', 'k1', 'val1')
95
+ subject.hset('key1', 'k2', 'val2')
96
+
97
+ expect {
98
+ subject.sort('key1')
99
+ }.to raise_error(Redis::CommandError)
100
+ end
101
+ end
102
+
103
+ context 'list' do
104
+ let(:key) { 'fake-redis-test:list_sort' }
105
+
106
+ before do
107
+ subject.rpush(key, '1')
108
+ subject.rpush(key, '2')
109
+ end
110
+
111
+ it_behaves_like 'sortable'
112
+ end
113
+
114
+ context 'set' do
115
+ let(:key) { 'ake-redis-test:set_sort' }
116
+
117
+ before do
118
+ subject.sadd(key, '1')
119
+ subject.sadd(key, '2')
120
+ end
121
+
122
+ it_behaves_like 'sortable'
123
+ end
124
+
125
+ context 'zset' do
126
+ let(:key) { 'fake-redis-test:zset_sor' }
127
+
128
+ before do
129
+ subject.zadd(key, 100, '1')
130
+ subject.zadd(key, 99, '2')
131
+ end
132
+
133
+ it_behaves_like 'sortable'
134
+ end
135
+ end
136
+ end
@@ -2,44 +2,44 @@ shared_examples 'sorted sets' do
2
2
  let(:infinity) { 1.0 / 0.0 }
3
3
 
4
4
  it 'should add a member to a sorted set, or update its score if it already exists' do
5
- subject.zadd('key', 1, 'val').should be_true
6
- subject.zscore('key', 'val').should eq(1.0)
5
+ expect(subject.zadd('key', 1, 'val')).to be_truthy
6
+ expect(subject.zscore('key', 'val')).to eq(1.0)
7
7
 
8
- subject.zadd('key', 2, 'val').should be_false
9
- subject.zscore('key', 'val').should eq(2.0)
8
+ expect(subject.zadd('key', 2, 'val')).to be_falsey
9
+ expect(subject.zscore('key', 'val')).to eq(2.0)
10
10
 
11
- subject.zadd('key2', 'inf', 'val').should be_true
12
- subject.zscore('key2', 'val').should eq(infinity)
11
+ expect(subject.zadd('key2', 'inf', 'val')).to be_truthy
12
+ expect(subject.zscore('key2', 'val')).to eq(infinity)
13
13
 
14
- subject.zadd('key3', '+inf', 'val').should be_true
15
- subject.zscore('key3', 'val').should eq(infinity)
14
+ expect(subject.zadd('key3', '+inf', 'val')).to be_truthy
15
+ expect(subject.zscore('key3', 'val')).to eq(infinity)
16
16
 
17
- subject.zadd('key4', '-inf', 'val').should be_true
18
- subject.zscore('key4', 'val').should eq(-infinity)
17
+ expect(subject.zadd('key4', '-inf', 'val')).to be_truthy
18
+ expect(subject.zscore('key4', 'val')).to eq(-infinity)
19
19
  end
20
20
 
21
21
  it 'should return a nil score for value not in a sorted set or empty key' do
22
22
  subject.zadd('key', 1, 'val')
23
23
 
24
- subject.zscore('key', 'val').should eq(1.0)
25
- subject.zscore('key', 'val2').should be_nil
26
- subject.zscore('key2', 'val').should be_nil
24
+ expect(subject.zscore('key', 'val')).to eq(1.0)
25
+ expect(subject.zscore('key', 'val2')).to be_nil
26
+ expect(subject.zscore('key2', 'val')).to be_nil
27
27
  end
28
28
 
29
29
  it 'should add multiple members to a sorted set, or update its score if it already exists' do
30
- subject.zadd('key', [1, 'val', 2, 'val2']).should eq(2)
31
- subject.zscore('key', 'val').should eq(1)
32
- subject.zscore('key', 'val2').should eq(2)
33
-
34
- subject.zadd('key', [[5, 'val'], [3, 'val3'], [4, 'val4']]).should eq(2)
35
- subject.zscore('key', 'val').should eq(5)
36
- subject.zscore('key', 'val2').should eq(2)
37
- subject.zscore('key', 'val3').should eq(3)
38
- subject.zscore('key', 'val4').should eq(4)
39
-
40
- subject.zadd('key', [[5, 'val5'], [3, 'val6']]).should eq(2)
41
- subject.zscore('key', 'val5').should eq(5)
42
- subject.zscore('key', 'val6').should eq(3)
30
+ expect(subject.zadd('key', [1, 'val', 2, 'val2'])).to eq(2)
31
+ expect(subject.zscore('key', 'val')).to eq(1)
32
+ expect(subject.zscore('key', 'val2')).to eq(2)
33
+
34
+ expect(subject.zadd('key', [[5, 'val'], [3, 'val3'], [4, 'val4']])).to eq(2)
35
+ expect(subject.zscore('key', 'val')).to eq(5)
36
+ expect(subject.zscore('key', 'val2')).to eq(2)
37
+ expect(subject.zscore('key', 'val3')).to eq(3)
38
+ expect(subject.zscore('key', 'val4')).to eq(4)
39
+
40
+ expect(subject.zadd('key', [[5, 'val5'], [3, 'val6']])).to eq(2)
41
+ expect(subject.zscore('key', 'val5')).to eq(5)
42
+ expect(subject.zscore('key', 'val6')).to eq(3)
43
43
  end
44
44
 
45
45
  it 'should error with wrong number of arguments when adding members' do
@@ -65,34 +65,34 @@ shared_examples 'sorted sets' do
65
65
  end
66
66
 
67
67
  it 'should allow floats as scores when adding or updating' do
68
- subject.zadd('key', 4.321, 'val').should be_true
69
- subject.zscore('key', 'val').should eq(4.321)
68
+ expect(subject.zadd('key', 4.321, 'val')).to be_truthy
69
+ expect(subject.zscore('key', 'val')).to eq(4.321)
70
70
 
71
- subject.zadd('key', 54.3210, 'val').should be_false
72
- subject.zscore('key', 'val').should eq(54.321)
71
+ expect(subject.zadd('key', 54.3210, 'val')).to be_falsey
72
+ expect(subject.zscore('key', 'val')).to eq(54.321)
73
73
  end
74
74
 
75
75
  it 'should remove members from sorted sets' do
76
- subject.zrem('key', 'val').should be_false
77
- subject.zadd('key', 1, 'val').should be_true
78
- subject.zrem('key', 'val').should be_true
76
+ expect(subject.zrem('key', 'val')).to be_falsey
77
+ expect(subject.zadd('key', 1, 'val')).to be_truthy
78
+ expect(subject.zrem('key', 'val')).to be_truthy
79
79
  end
80
80
 
81
81
  it 'should remove multiple members from sorted sets' do
82
- subject.zrem('key2', %w(val)).should eq(0)
83
- subject.zrem('key2', %w(val val2 val3)).should eq(0)
82
+ expect(subject.zrem('key2', %w(val))).to eq(0)
83
+ expect(subject.zrem('key2', %w(val val2 val3))).to eq(0)
84
84
 
85
85
  subject.zadd('key2', 1, 'val')
86
86
  subject.zadd('key2', 1, 'val2')
87
87
  subject.zadd('key2', 1, 'val3')
88
88
 
89
- subject.zrem('key2', %w(val val2 val3 val4)).should eq(3)
89
+ expect(subject.zrem('key2', %w(val val2 val3 val4))).to eq(3)
90
90
  end
91
91
 
92
92
  it "should remove sorted set's key when it is empty" do
93
93
  subject.zadd('key', 1, 'val')
94
94
  subject.zrem('key', 'val')
95
- subject.exists('key').should be_false
95
+ expect(subject.exists('key')).to be_falsey
96
96
  end
97
97
 
98
98
  it 'should get the number of members in a sorted set' do
@@ -100,7 +100,7 @@ shared_examples 'sorted sets' do
100
100
  subject.zadd('key', 2, 'val1')
101
101
  subject.zadd('key', 5, 'val3')
102
102
 
103
- subject.zcard('key').should eq(3)
103
+ expect(subject.zcard('key')).to eq(3)
104
104
  end
105
105
 
106
106
  it 'should count the members in a sorted set with scores within the given values' do
@@ -108,27 +108,27 @@ shared_examples 'sorted sets' do
108
108
  subject.zadd('key', 2, 'val2')
109
109
  subject.zadd('key', 3, 'val3')
110
110
 
111
- subject.zcount('key', 2, 3).should eq(2)
111
+ expect(subject.zcount('key', 2, 3)).to eq(2)
112
112
  end
113
113
 
114
114
  it 'should increment the score of a member in a sorted set' do
115
115
  subject.zadd('key', 1, 'val1')
116
- subject.zincrby('key', 2, 'val1').should eq(3)
117
- subject.zscore('key', 'val1').should eq(3)
116
+ expect(subject.zincrby('key', 2, 'val1')).to eq(3)
117
+ expect(subject.zscore('key', 'val1')).to eq(3)
118
118
  end
119
119
 
120
120
  it 'initializes the sorted set if the key wasnt already set' do
121
- subject.zincrby('key', 1, 'val1').should eq(1)
121
+ expect(subject.zincrby('key', 1, 'val1')).to eq(1)
122
122
  end
123
123
 
124
124
  it 'should convert the key to a string for zscore' do
125
125
  subject.zadd('key', 1, 1)
126
- subject.zscore('key', 1).should eq(1)
126
+ expect(subject.zscore('key', 1)).to eq(1)
127
127
  end
128
128
 
129
129
  it 'should handle infinity values when incrementing a sorted set key' do
130
- subject.zincrby('bar', '+inf', 's2').should eq(infinity)
131
- subject.zincrby('bar', '-inf', 's1').should eq(-infinity)
130
+ expect(subject.zincrby('bar', '+inf', 's2')).to eq(infinity)
131
+ expect(subject.zincrby('bar', '-inf', 's1')).to eq(-infinity)
132
132
  end
133
133
 
134
134
  it 'should return a range of members in a sorted set, by index' do
@@ -136,10 +136,10 @@ shared_examples 'sorted sets' do
136
136
  subject.zadd('key', 2, 'two')
137
137
  subject.zadd('key', 3, 'three')
138
138
 
139
- subject.zrange('key', 0, -1).should eq(['one', 'two', 'three'])
140
- subject.zrange('key', 1, 2).should eq(['two', 'three'])
141
- subject.zrange('key', 0, -1, with_scores: true).should eq([['one', 1], ['two', 2], ['three', 3]])
142
- subject.zrange('key', 1, 2, with_scores: true).should eq([['two', 2], ['three', 3]])
139
+ expect(subject.zrange('key', 0, -1)).to eq(['one', 'two', 'three'])
140
+ expect(subject.zrange('key', 1, 2)).to eq(['two', 'three'])
141
+ expect(subject.zrange('key', 0, -1, with_scores: true)).to eq([['one', 1], ['two', 2], ['three', 3]])
142
+ expect(subject.zrange('key', 1, 2, with_scores: true)).to eq([['two', 2], ['three', 3]])
143
143
  end
144
144
 
145
145
  it 'should sort zrange results logically' do
@@ -147,8 +147,8 @@ shared_examples 'sorted sets' do
147
147
  subject.zadd('key', 5, 'val3')
148
148
  subject.zadd('key', 5, 'val1')
149
149
 
150
- subject.zrange('key', 0, -1).should eq(%w(val1 val2 val3))
151
- subject.zrange('key', 0, -1, with_scores: true).should eq([['val1', 5], ['val2', 5], ['val3', 5]])
150
+ expect(subject.zrange('key', 0, -1)).to eq(%w(val1 val2 val3))
151
+ expect(subject.zrange('key', 0, -1, with_scores: true)).to eq([['val1', 5], ['val2', 5], ['val3', 5]])
152
152
  end
153
153
 
154
154
  it 'should return a reversed range of members in a sorted set, by index' do
@@ -156,10 +156,10 @@ shared_examples 'sorted sets' do
156
156
  subject.zadd('key', 2, 'two')
157
157
  subject.zadd('key', 3, 'three')
158
158
 
159
- subject.zrevrange('key', 0, -1).should eq(['three', 'two', 'one'])
160
- subject.zrevrange('key', 1, 2).should eq(['two', 'one'])
161
- subject.zrevrange('key', 0, -1, with_scores: true).should eq([['three', 3], ['two', 2], ['one', 1]])
162
- subject.zrevrange('key', 0, -1, with_scores: true).should eq([['three', 3], ['two', 2], ['one', 1]])
159
+ expect(subject.zrevrange('key', 0, -1)).to eq(['three', 'two', 'one'])
160
+ expect(subject.zrevrange('key', 1, 2)).to eq(['two', 'one'])
161
+ expect(subject.zrevrange('key', 0, -1, with_scores: true)).to eq([['three', 3], ['two', 2], ['one', 1]])
162
+ expect(subject.zrevrange('key', 0, -1, with_scores: true)).to eq([['three', 3], ['two', 2], ['one', 1]])
163
163
  end
164
164
 
165
165
  it 'should return a range of members in a sorted set, by score' do
@@ -167,21 +167,21 @@ shared_examples 'sorted sets' do
167
167
  subject.zadd('key', 2, 'two')
168
168
  subject.zadd('key', 3, 'three')
169
169
 
170
- subject.zrangebyscore('key', 0, 100).should eq(['one', 'two', 'three'])
171
- subject.zrangebyscore('key', 1, 2).should eq(['one', 'two'])
172
- subject.zrangebyscore('key', 1, '(2').should eq(['one'])
173
- subject.zrangebyscore('key', '(1', 2).should eq(['two'])
174
- subject.zrangebyscore('key', '(1', '(2').should eq([])
175
- subject.zrangebyscore('key', 0, 100, with_scores: true).should eq([['one', 1], ['two', 2], ['three', 3]])
176
- subject.zrangebyscore('key', 1, 2, with_scores: true).should eq([['one', 1], ['two', 2]])
177
- subject.zrangebyscore('key', 0, 100, limit: [0, 1]).should eq(['one'])
178
- subject.zrangebyscore('key', 0, 100, limit: [0, -1]).should eq(['one', 'two', 'three'])
179
- subject.zrangebyscore('key', 0, 100, limit: [1, -1], with_scores: true).should eq([['two', 2], ['three', 3]])
180
- subject.zrangebyscore('key', '-inf', '+inf').should eq(['one', 'two', 'three'])
181
- subject.zrangebyscore('key', 2, '+inf').should eq(['two', 'three'])
182
- subject.zrangebyscore('key', '-inf', 2).should eq(['one', 'two'])
183
-
184
- subject.zrangebyscore('badkey', 1, 2).should eq([])
170
+ expect(subject.zrangebyscore('key', 0, 100)).to eq(['one', 'two', 'three'])
171
+ expect(subject.zrangebyscore('key', 1, 2)).to eq(['one', 'two'])
172
+ expect(subject.zrangebyscore('key', 1, '(2')).to eq(['one'])
173
+ expect(subject.zrangebyscore('key', '(1', 2)).to eq(['two'])
174
+ expect(subject.zrangebyscore('key', '(1', '(2')).to eq([])
175
+ expect(subject.zrangebyscore('key', 0, 100, with_scores: true)).to eq([['one', 1], ['two', 2], ['three', 3]])
176
+ expect(subject.zrangebyscore('key', 1, 2, with_scores: true)).to eq([['one', 1], ['two', 2]])
177
+ expect(subject.zrangebyscore('key', 0, 100, limit: [0, 1])).to eq(['one'])
178
+ expect(subject.zrangebyscore('key', 0, 100, limit: [0, -1])).to eq(['one', 'two', 'three'])
179
+ expect(subject.zrangebyscore('key', 0, 100, limit: [1, -1], with_scores: true)).to eq([['two', 2], ['three', 3]])
180
+ expect(subject.zrangebyscore('key', '-inf', '+inf')).to eq(['one', 'two', 'three'])
181
+ expect(subject.zrangebyscore('key', 2, '+inf')).to eq(['two', 'three'])
182
+ expect(subject.zrangebyscore('key', '-inf', 2)).to eq(['one', 'two'])
183
+
184
+ expect(subject.zrangebyscore('badkey', 1, 2)).to eq([])
185
185
  end
186
186
 
187
187
  it 'should return a reversed range of members in a sorted set, by score' do
@@ -189,13 +189,13 @@ shared_examples 'sorted sets' do
189
189
  subject.zadd('key', 2, 'two')
190
190
  subject.zadd('key', 3, 'three')
191
191
 
192
- subject.zrevrangebyscore('key', 100, 0).should eq(['three', 'two', 'one'])
193
- subject.zrevrangebyscore('key', 2, 1).should eq(['two', 'one'])
194
- subject.zrevrangebyscore('key', 1, 2).should be_empty
195
- subject.zrevrangebyscore('key', 2, 1, with_scores: true).should eq([['two', 2.0], ['one', 1.0]])
196
- subject.zrevrangebyscore('key', 100, 0, limit: [0, 1]).should eq(['three'])
197
- subject.zrevrangebyscore('key', 100, 0, limit: [0, -1]).should eq(['three', 'two', 'one'])
198
- subject.zrevrangebyscore('key', 100, 0, limit: [1, -1], with_scores: true).should eq([['two', 2.0], ['one', 1.0]])
192
+ expect(subject.zrevrangebyscore('key', 100, 0)).to eq(['three', 'two', 'one'])
193
+ expect(subject.zrevrangebyscore('key', 2, 1)).to eq(['two', 'one'])
194
+ expect(subject.zrevrangebyscore('key', 1, 2)).to be_empty
195
+ expect(subject.zrevrangebyscore('key', 2, 1, with_scores: true)).to eq([['two', 2.0], ['one', 1.0]])
196
+ expect(subject.zrevrangebyscore('key', 100, 0, limit: [0, 1])).to eq(['three'])
197
+ expect(subject.zrevrangebyscore('key', 100, 0, limit: [0, -1])).to eq(['three', 'two', 'one'])
198
+ expect(subject.zrevrangebyscore('key', 100, 0, limit: [1, -1], with_scores: true)).to eq([['two', 2.0], ['one', 1.0]])
199
199
  end
200
200
 
201
201
  it 'should determine the index of a member in a sorted set' do
@@ -203,8 +203,8 @@ shared_examples 'sorted sets' do
203
203
  subject.zadd('key', 2, 'two')
204
204
  subject.zadd('key', 3, 'three')
205
205
 
206
- subject.zrank('key', 'three').should eq(2)
207
- subject.zrank('key', 'four').should be_nil
206
+ expect(subject.zrank('key', 'three')).to eq(2)
207
+ expect(subject.zrank('key', 'four')).to be_nil
208
208
  end
209
209
 
210
210
  it 'should determine the reversed index of a member in a sorted set' do
@@ -212,16 +212,16 @@ shared_examples 'sorted sets' do
212
212
  subject.zadd('key', 2, 'two')
213
213
  subject.zadd('key', 3, 'three')
214
214
 
215
- subject.zrevrank('key', 'three').should eq(0)
216
- subject.zrevrank('key', 'four').should be_nil
215
+ expect(subject.zrevrank('key', 'three')).to eq(0)
216
+ expect(subject.zrevrank('key', 'four')).to be_nil
217
217
  end
218
218
 
219
219
  it 'should not raise errors for zrank() on accessing a non-existing key in a sorted set' do
220
- subject.zrank('no_such_key', 'no_suck_id').should be_nil
220
+ expect(subject.zrank('no_such_key', 'no_suck_id')).to be_nil
221
221
  end
222
222
 
223
223
  it 'should not raise errors for zrevrank() on accessing a non-existing key in a sorted set' do
224
- subject.zrevrank('no_such_key', 'no_suck_id').should be_nil
224
+ expect(subject.zrevrank('no_such_key', 'no_suck_id')).to be_nil
225
225
  end
226
226
 
227
227
  describe '#zinterstore' do
@@ -236,53 +236,53 @@ shared_examples 'sorted sets' do
236
236
  end
237
237
 
238
238
  it 'should intersect two keys with custom scores' do
239
- subject.zinterstore('out', ['key1', 'key2']).should eq(2)
240
- subject.zrange('out', 0, -1, with_scores: true).should eq([['two', (2 + 5)], ['three', (3 + 7)]])
239
+ expect(subject.zinterstore('out', ['key1', 'key2'])).to eq(2)
240
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['two', (2 + 5)], ['three', (3 + 7)]])
241
241
  end
242
242
 
243
243
  it 'should intersect two keys with a default score' do
244
- subject.zinterstore('out', ['key1', 'key3']).should eq(2)
245
- subject.zrange('out', 0, -1, with_scores: true).should eq([['one', (1 + 1)], ['two', (2 + 1)]])
244
+ expect(subject.zinterstore('out', ['key1', 'key3'])).to eq(2)
245
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['one', (1 + 1)], ['two', (2 + 1)]])
246
246
  end
247
247
 
248
248
  it 'should intersect more than two keys' do
249
- subject.zinterstore('out', ['key1', 'key2', 'key3']).should eq(1)
250
- subject.zrange('out', 0, -1, with_scores: true).should eq([['two', (2 + 5 + 1)]])
249
+ expect(subject.zinterstore('out', ['key1', 'key2', 'key3'])).to eq(1)
250
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['two', (2 + 5 + 1)]])
251
251
  end
252
252
 
253
253
  it 'should not intersect an unknown key' do
254
- subject.zinterstore('out', ['key1', 'no_key']).should eq(0)
255
- subject.zrange('out', 0, -1, with_scores: true).should be_empty
254
+ expect(subject.zinterstore('out', ['key1', 'no_key'])).to eq(0)
255
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to be_empty
256
256
  end
257
257
 
258
258
  it 'should intersect two keys by minimum values' do
259
- subject.zinterstore('out', ['key1', 'key2'], aggregate: :min).should eq(2)
260
- subject.zrange('out', 0, -1, with_scores: true).should eq([['two', 2], ['three', 3]])
259
+ expect(subject.zinterstore('out', ['key1', 'key2'], aggregate: :min)).to eq(2)
260
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['two', 2], ['three', 3]])
261
261
  end
262
262
 
263
263
  it 'should intersect two keys by maximum values' do
264
- subject.zinterstore('out', ['key1', 'key2'], aggregate: :max).should eq(2)
265
- subject.zrange('out', 0, -1, with_scores: true).should eq([['two', 5], ['three', 7]])
264
+ expect(subject.zinterstore('out', ['key1', 'key2'], aggregate: :max)).to eq(2)
265
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['two', 5], ['three', 7]])
266
266
  end
267
267
 
268
268
  it 'should intersect two keys by explicitly summing values' do
269
- subject.zinterstore('out', %w(key1 key2), aggregate: :sum).should eq(2)
270
- subject.zrange('out', 0, -1, with_scores: true).should eq([['two', (2 + 5)], ['three', (3 + 7)]])
269
+ expect(subject.zinterstore('out', %w(key1 key2), aggregate: :sum)).to eq(2)
270
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['two', (2 + 5)], ['three', (3 + 7)]])
271
271
  end
272
272
 
273
273
  it 'should intersect two keys with weighted values' do
274
- subject.zinterstore('out', %w(key1 key2), weights: [10, 1]).should eq(2)
275
- subject.zrange('out', 0, -1, with_scores: true).should eq([['two', (2 * 10 + 5)], ['three', (3 * 10 + 7)]])
274
+ expect(subject.zinterstore('out', %w(key1 key2), weights: [10, 1])).to eq(2)
275
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['two', (2 * 10 + 5)], ['three', (3 * 10 + 7)]])
276
276
  end
277
277
 
278
278
  it 'should intersect two keys with weighted minimum values' do
279
- subject.zinterstore('out', %w(key1 key2), weights: [10, 1], aggregate: :min).should eq(2)
280
- subject.zrange('out', 0, -1, with_scores: true).should eq([['two', 5], ['three', 7]])
279
+ expect(subject.zinterstore('out', %w(key1 key2), weights: [10, 1], aggregate: :min)).to eq(2)
280
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['two', 5], ['three', 7]])
281
281
  end
282
282
 
283
283
  it 'should intersect two keys with weighted maximum values' do
284
- subject.zinterstore('out', %w(key1 key2), weights: [10, 1], aggregate: :max).should eq(2)
285
- subject.zrange('out', 0, -1, with_scores: true).should eq([['two', (2 * 10)], ['three', (3 * 10)]])
284
+ expect(subject.zinterstore('out', %w(key1 key2), weights: [10, 1], aggregate: :max)).to eq(2)
285
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['two', (2 * 10)], ['three', (3 * 10)]])
286
286
  end
287
287
 
288
288
  it 'should error without enough weights given' do
@@ -314,23 +314,23 @@ shared_examples 'sorted sets' do
314
314
  subject.zadd('key', 2, 'two')
315
315
  subject.zadd('key', 3, 'three')
316
316
 
317
- subject.zremrangebyscore('key', 0, 2).should eq(2)
318
- subject.zcard('key').should eq(1)
317
+ expect(subject.zremrangebyscore('key', 0, 2)).to eq(2)
318
+ expect(subject.zcard('key')).to eq(1)
319
319
  end
320
320
 
321
321
  it 'should remove items by score with infinity' do # Issue #50
322
322
  subject.zadd('key', 10.0, 'one')
323
323
  subject.zadd('key', 20.0, 'two')
324
324
  subject.zadd('key', 30.0, 'three')
325
- subject.zremrangebyscore('key', '-inf', '+inf').should eq(3)
326
- subject.zcard('key').should eq(0)
327
- subject.zscore('key', 'one').should be_nil
328
- subject.zscore('key', 'two').should be_nil
329
- subject.zscore('key', 'three').should be_nil
325
+ expect(subject.zremrangebyscore('key', '-inf', '+inf')).to eq(3)
326
+ expect(subject.zcard('key')).to eq(0)
327
+ expect(subject.zscore('key', 'one')).to be_nil
328
+ expect(subject.zscore('key', 'two')).to be_nil
329
+ expect(subject.zscore('key', 'three')).to be_nil
330
330
  end
331
331
 
332
332
  it 'should return 0 if the key did not exist' do
333
- subject.zremrangebyscore('key', 0, 2).should eq(0)
333
+ expect(subject.zremrangebyscore('key', 0, 2)).to eq(0)
334
334
  end
335
335
  end
336
336
 
@@ -340,8 +340,8 @@ shared_examples 'sorted sets' do
340
340
  subject.zadd('key', 2, 'two')
341
341
  subject.zadd('key', 3, 'three')
342
342
 
343
- subject.zremrangebyrank('key', 0, 1).should eq(2)
344
- subject.zcard('key').should eq(1)
343
+ expect(subject.zremrangebyrank('key', 0, 1)).to eq(2)
344
+ expect(subject.zcard('key')).to eq(1)
345
345
  end
346
346
 
347
347
  it 'handles out of range requests' do
@@ -349,8 +349,12 @@ shared_examples 'sorted sets' do
349
349
  subject.zadd('key', 2, 'two')
350
350
  subject.zadd('key', 3, 'three')
351
351
 
352
- subject.zremrangebyrank('key', 25, -1).should eq(0)
353
- subject.zcard('key').should eq(3)
352
+ expect(subject.zremrangebyrank('key', 25, -1)).to eq(0)
353
+ expect(subject.zcard('key')).to eq(3)
354
+ end
355
+
356
+ it "should return 0 if the key didn't exist" do
357
+ expect(subject.zremrangebyrank('key', 0, 1)).to eq(0)
354
358
  end
355
359
  end
356
360
 
@@ -366,53 +370,53 @@ shared_examples 'sorted sets' do
366
370
  end
367
371
 
368
372
  it 'should union two keys with custom scores' do
369
- subject.zunionstore('out', %w(key1 key2)).should eq(3)
370
- subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', (2 + 5)], ['val3', (3 + 7)]])
373
+ expect(subject.zunionstore('out', %w(key1 key2))).to eq(3)
374
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['val1', 1], ['val2', (2 + 5)], ['val3', (3 + 7)]])
371
375
  end
372
376
 
373
377
  it 'should union two keys with a default score' do
374
- subject.zunionstore('out', %w(key1 key3)).should eq(3)
375
- subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', (1 + 1)], ['val2', (2 + 1)], ['val3', 3]])
378
+ expect(subject.zunionstore('out', %w(key1 key3))).to eq(3)
379
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['val1', (1 + 1)], ['val2', (2 + 1)], ['val3', 3]])
376
380
  end
377
381
 
378
382
  it 'should union more than two keys' do
379
- subject.zunionstore('out', %w(key1 key2 key3)).should eq(3)
380
- subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', (1 + 1)], ['val2', (2 + 5 + 1)], ['val3', (3 + 7)]])
383
+ expect(subject.zunionstore('out', %w(key1 key2 key3))).to eq(3)
384
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['val1', (1 + 1)], ['val2', (2 + 5 + 1)], ['val3', (3 + 7)]])
381
385
  end
382
386
 
383
387
  it 'should union with an unknown key' do
384
- subject.zunionstore('out', %w(key1 no_key)).should eq(3)
385
- subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', 2], ['val3', 3]])
388
+ expect(subject.zunionstore('out', %w(key1 no_key))).to eq(3)
389
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['val1', 1], ['val2', 2], ['val3', 3]])
386
390
  end
387
391
 
388
392
  it 'should union two keys by minimum values' do
389
- subject.zunionstore('out', %w(key1 key2), aggregate: :min).should eq(3)
390
- subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', 2], ['val3', 3]])
393
+ expect(subject.zunionstore('out', %w(key1 key2), aggregate: :min)).to eq(3)
394
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['val1', 1], ['val2', 2], ['val3', 3]])
391
395
  end
392
396
 
393
397
  it 'should union two keys by maximum values' do
394
- subject.zunionstore('out', %w(key1 key2), aggregate: :max).should eq(3)
395
- subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', 5], ['val3', 7]])
398
+ expect(subject.zunionstore('out', %w(key1 key2), aggregate: :max)).to eq(3)
399
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['val1', 1], ['val2', 5], ['val3', 7]])
396
400
  end
397
401
 
398
402
  it 'should union two keys by explicitly summing values' do
399
- subject.zunionstore('out', %w(key1 key2), aggregate: :sum).should eq(3)
400
- subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', (2 + 5)], ['val3', (3 + 7)]])
403
+ expect(subject.zunionstore('out', %w(key1 key2), aggregate: :sum)).to eq(3)
404
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['val1', 1], ['val2', (2 + 5)], ['val3', (3 + 7)]])
401
405
  end
402
406
 
403
407
  it 'should union two keys with weighted values' do
404
- subject.zunionstore('out', %w(key1 key2), :weights => [10, 1]).should eq(3)
405
- subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', (1 * 10)], ['val2', (2 * 10 + 5)], ['val3', (3 * 10 + 7)]])
408
+ expect(subject.zunionstore('out', %w(key1 key2), :weights => [10, 1])).to eq(3)
409
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['val1', (1 * 10)], ['val2', (2 * 10 + 5)], ['val3', (3 * 10 + 7)]])
406
410
  end
407
411
 
408
412
  it 'should union two keys with weighted minimum values' do
409
- subject.zunionstore('out', %w(key1 key2), weights: [10, 1], aggregate: :min).should eq(3)
410
- subject.zrange('out', 0, -1, with_scores: true).should eq([['val2', 5], ['val3', 7], ['val1', (1 * 10)]])
413
+ expect(subject.zunionstore('out', %w(key1 key2), weights: [10, 1], aggregate: :min)).to eq(3)
414
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['val2', 5], ['val3', 7], ['val1', (1 * 10)]])
411
415
  end
412
416
 
413
417
  it 'should union two keys with weighted maximum values' do
414
- subject.zunionstore('out', %w(key1 key2), weights: [10, 1], aggregate: :max).should eq(3)
415
- subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', (1 * 10)], ['val2', (2 * 10)], ['val3', (3 * 10)]])
418
+ expect(subject.zunionstore('out', %w(key1 key2), weights: [10, 1], aggregate: :max)).to eq(3)
419
+ expect(subject.zrange('out', 0, -1, with_scores: true)).to eq([['val1', (1 * 10)], ['val2', (2 * 10)], ['val3', (3 * 10)]])
416
420
  end
417
421
 
418
422
  it 'should error without enough weights given' do
@@ -441,7 +445,7 @@ shared_examples 'sorted sets' do
441
445
  it 'zrem should remove members add by zadd' do
442
446
  subject.zadd('key1', 1, 3)
443
447
  subject.zrem('key1', 3)
444
- subject.zscore('key1', 3).should be_nil
448
+ expect(subject.zscore('key1', 3)).to be_nil
445
449
  end
446
450
 
447
451
  #it 'should remove all members in a sorted set within the given indexes'