rediska 0.0.11 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,42 +3,42 @@ shared_examples 'strings' do
3
3
  subject.set('key1', 'Hello')
4
4
  subject.append('key1', ' World')
5
5
 
6
- subject.get('key1').should eq('Hello World')
6
+ expect(subject.get('key1')).to eq('Hello World')
7
7
  end
8
8
 
9
9
  it 'should decrement the integer value of a key by one' do
10
10
  subject.set('counter', '1')
11
11
  subject.decr('counter')
12
12
 
13
- subject.get('counter').should eq('0')
13
+ expect(subject.get('counter')).to eq('0')
14
14
  end
15
15
 
16
16
  it 'should decrement the integer value of a key by the given number' do
17
17
  subject.set('counter', '10')
18
18
  subject.decrby('counter', '5')
19
19
 
20
- subject.get('counter').should eq('5')
20
+ expect(subject.get('counter')).to eq('5')
21
21
  end
22
22
 
23
23
  it 'should get the value of a key' do
24
- subject.get('key2').should be_nil
24
+ expect(subject.get('key2')).to be_nil
25
25
  end
26
26
 
27
27
  it 'should returns the bit value at offset in the string value stored at key' do
28
28
  subject.set('key1', 'a')
29
29
 
30
- subject.getbit('key1', 1).should eq(1)
31
- subject.getbit('key1', 2).should eq(1)
32
- subject.getbit('key1', 3).should eq(0)
33
- subject.getbit('key1', 4).should eq(0)
34
- subject.getbit('key1', 5).should eq(0)
35
- subject.getbit('key1', 6).should eq(0)
36
- subject.getbit('key1', 7).should eq(1)
30
+ expect(subject.getbit('key1', 1)).to eq(1)
31
+ expect(subject.getbit('key1', 2)).to eq(1)
32
+ expect(subject.getbit('key1', 3)).to eq(0)
33
+ expect(subject.getbit('key1', 4)).to eq(0)
34
+ expect(subject.getbit('key1', 5)).to eq(0)
35
+ expect(subject.getbit('key1', 6)).to eq(0)
36
+ expect(subject.getbit('key1', 7)).to eq(1)
37
37
  end
38
38
 
39
39
  it 'should allow direct bit manipulation even if the string is not set' do
40
40
  subject.setbit('key1', 10, 1)
41
- subject.getbit('key1', 10).should eq(1)
41
+ expect(subject.getbit('key1', 10)).to eq(1)
42
42
  end
43
43
 
44
44
  context 'when a bit is previously set to 0' do
@@ -47,11 +47,11 @@ shared_examples 'strings' do
47
47
  end
48
48
 
49
49
  it 'setting it to 1 returns 0' do
50
- subject.setbit('key1', 10, 1).should eq(0)
50
+ expect(subject.setbit('key1', 10, 1)).to eq(0)
51
51
  end
52
52
 
53
53
  it 'setting it to 0 returns 0' do
54
- subject.setbit('key1', 10, 0).should eq(0)
54
+ expect(subject.setbit('key1', 10, 0)).to eq(0)
55
55
  end
56
56
  end
57
57
 
@@ -61,95 +61,95 @@ shared_examples 'strings' do
61
61
  end
62
62
 
63
63
  it 'setting it to 0 returns 1' do
64
- subject.setbit('key1', 10, 0).should eq(1)
64
+ expect(subject.setbit('key1', 10, 0)).to eq(1)
65
65
  end
66
66
 
67
67
  it 'setting it to 1 returns 1' do
68
- subject.setbit('key1', 10, 1).should eq(1)
68
+ expect(subject.setbit('key1', 10, 1)).to eq(1)
69
69
  end
70
70
  end
71
71
 
72
72
  it 'should get a substring of the string stored at a key' do
73
73
  subject.set('key1', 'This a message')
74
74
 
75
- subject.getrange('key1', 0, 3).should eq('This')
76
- subject.substr('key1', 0, 3).should eq('This')
75
+ expect(subject.getrange('key1', 0, 3)).to eq('This')
76
+ expect(subject.substr('key1', 0, 3)).to eq('This')
77
77
  end
78
78
 
79
79
  it 'should set the string value of a key and return its old value' do
80
80
  subject.set('key1','value1')
81
81
 
82
- subject.getset('key1', 'value2').should eq('value1')
83
- subject.get('key1').should eq('value2')
82
+ expect(subject.getset('key1', 'value2')).to eq('value1')
83
+ expect(subject.get('key1')).to eq('value2')
84
84
  end
85
85
 
86
86
  it 'should return nil for #getset if the key does not exist when setting' do
87
- subject.getset('key1', 'value1').should be_nil
88
- subject.get('key1').should eq('value1')
87
+ expect(subject.getset('key1', 'value1')).to be_nil
88
+ expect(subject.get('key1')).to eq('value1')
89
89
  end
90
90
 
91
91
  it 'should increment the integer value of a key by one' do
92
92
  subject.set('counter', '1')
93
- subject.incr('counter').should eq(2)
93
+ expect(subject.incr('counter')).to eq(2)
94
94
 
95
- subject.get('counter').should eq('2')
95
+ expect(subject.get('counter')).to eq('2')
96
96
  end
97
97
 
98
98
  it 'should not change the expire value of the key during incr' do
99
99
  subject.set('counter', '1')
100
- subject.expire('counter', 600).should be_true
100
+ expect(subject.expire('counter', 600)).to be_truthy
101
101
 
102
- subject.ttl('counter').should eq(600)
103
- subject.incr('counter').should eq(2)
104
- subject.ttl('counter').should be_within(10).of(600)
102
+ expect(subject.ttl('counter')).to eq(600)
103
+ expect(subject.incr('counter')).to eq(2)
104
+ expect(subject.ttl('counter')).to be_within(10).of(600)
105
105
  end
106
106
 
107
107
  it 'should decrement the integer value of a key by one' do
108
108
  subject.set('counter', '1')
109
- subject.decr('counter').should eq(0)
109
+ expect(subject.decr('counter')).to eq(0)
110
110
 
111
- subject.get('counter').should eq('0')
111
+ expect(subject.get('counter')).to eq('0')
112
112
  end
113
113
 
114
114
  it 'should not change the expire value of the key during decr' do
115
115
  subject.set('counter', '2')
116
- subject.expire('counter', 600).should be_true
116
+ expect(subject.expire('counter', 600)).to be_truthy
117
117
 
118
- subject.ttl('counter').should eq(600)
119
- subject.decr('counter').should eq(1)
120
- subject.ttl('counter').should be_within(10).of(600)
118
+ expect(subject.ttl('counter')).to eq(600)
119
+ expect(subject.decr('counter')).to eq(1)
120
+ expect(subject.ttl('counter')).to be_within(10).of(600)
121
121
  end
122
122
 
123
123
  it 'should increment the integer value of a key by the given number' do
124
124
  subject.set('counter', '10')
125
- subject.incrby('counter', '5').should eq(15)
126
- subject.incrby('counter', 2).should eq(17)
127
- subject.get('counter').should eq('17')
125
+ expect(subject.incrby('counter', '5')).to eq(15)
126
+ expect(subject.incrby('counter', 2)).to eq(17)
127
+ expect(subject.get('counter')).to eq('17')
128
128
  end
129
129
 
130
130
  it 'should not change the expire value of the key during incrby' do
131
131
  subject.set('counter', '1')
132
- subject.expire('counter', 600).should be_true
132
+ expect(subject.expire('counter', 600)).to be_truthy
133
133
 
134
- subject.ttl('counter').should eq(600)
135
- subject.incrby('counter', '5').should eq(6)
136
- subject.ttl('counter').should be_within(10).of(600)
134
+ expect(subject.ttl('counter')).to eq(600)
135
+ expect(subject.incrby('counter', '5')).to eq(6)
136
+ expect(subject.ttl('counter')).to be_within(10).of(600)
137
137
  end
138
138
 
139
139
  it 'should decrement the integer value of a key by the given number' do
140
140
  subject.set('counter', '10')
141
- subject.decrby('counter', '5').should eq(5)
142
- subject.decrby('counter', 2).should eq(3)
143
- subject.get('counter').should eq('3')
141
+ expect(subject.decrby('counter', '5')).to eq(5)
142
+ expect(subject.decrby('counter', 2)).to eq(3)
143
+ expect(subject.get('counter')).to eq('3')
144
144
  end
145
145
 
146
146
  it 'should not change the expire value of the key during decrby' do
147
147
  subject.set('counter', '8')
148
- subject.expire('counter', 600).should be_true
148
+ expect(subject.expire('counter', 600)).to be_truthy
149
149
 
150
- subject.ttl('counter').should eq(600)
151
- subject.decrby('counter', '3').should eq(5)
152
- subject.ttl('counter').should be_within(10).of(600)
150
+ expect(subject.ttl('counter')).to eq(600)
151
+ expect(subject.decrby('counter', '3')).to eq(5)
152
+ expect(subject.ttl('counter')).to be_within(10).of(600)
153
153
  end
154
154
 
155
155
  it 'should get the values of all the given keys' do
@@ -157,16 +157,16 @@ shared_examples 'strings' do
157
157
  subject.set('key2', 'value2')
158
158
  subject.set('key3', 'value3')
159
159
 
160
- subject.mget('key1', 'key2', 'key3').should eq(['value1', 'value2', 'value3'])
161
- subject.mget(['key1', 'key2', 'key3']).should eq(['value1', 'value2', 'value3'])
160
+ expect(subject.mget('key1', 'key2', 'key3')).to eq(['value1', 'value2', 'value3'])
161
+ expect(subject.mget(['key1', 'key2', 'key3'])).to eq(['value1', 'value2', 'value3'])
162
162
  end
163
163
 
164
164
  it 'returns nil for non existent keys' do
165
165
  subject.set('key1', 'value1')
166
166
  subject.set('key3', 'value3')
167
167
 
168
- subject.mget('key1', 'key2', 'key3', 'key4').should eq(['value1', nil, 'value3', nil])
169
- subject.mget(['key1', 'key2', 'key3', 'key4']).should eq(['value1', nil, 'value3', nil])
168
+ expect(subject.mget('key1', 'key2', 'key3', 'key4')).to eq(['value1', nil, 'value3', nil])
169
+ expect(subject.mget(['key1', 'key2', 'key3', 'key4'])).to eq(['value1', nil, 'value3', nil])
170
170
  end
171
171
 
172
172
  it 'raises an argument error when not passed any fields' do
@@ -180,8 +180,8 @@ shared_examples 'strings' do
180
180
  it 'should set multiple keys to multiple values' do
181
181
  subject.mset(:key1, 'value1', :key2, 'value2')
182
182
 
183
- subject.get('key1').should eq('value1')
184
- subject.get('key2').should eq('value2')
183
+ expect(subject.get('key1')).to eq('value1')
184
+ expect(subject.get('key2')).to eq('value2')
185
185
  end
186
186
 
187
187
  it 'should raise error if command arguments count is wrong' do
@@ -197,51 +197,51 @@ shared_examples 'strings' do
197
197
  subject.mset(:key1, 'value', :key2)
198
198
  }.to raise_error(Redis::CommandError, 'ERR wrong number of arguments for MSET')
199
199
 
200
- subject.get('key1').should be_nil
201
- subject.get('key2').should be_nil
200
+ expect(subject.get('key1')).to be_nil
201
+ expect(subject.get('key2')).to be_nil
202
202
  end
203
203
 
204
204
  it 'should set multiple keys to multiple values, only if none of the keys exist' do
205
- subject.msetnx(:key1, 'value1', :key2, 'value2').should be_true
206
- subject.msetnx(:key1, 'value3', :key2, 'value4').should be_false
205
+ expect(subject.msetnx(:key1, 'value1', :key2, 'value2')).to be_truthy
206
+ expect(subject.msetnx(:key1, 'value3', :key2, 'value4')).to be_falsey
207
207
 
208
- subject.get('key1').should eq('value1')
209
- subject.get('key2').should eq('value2')
208
+ expect(subject.get('key1')).to eq('value1')
209
+ expect(subject.get('key2')).to eq('value2')
210
210
  end
211
211
 
212
212
  it 'should set multiple keys to multiple values with a hash' do
213
213
  subject.mapped_mset(key1: 'value1', key2: 'value2')
214
214
 
215
- subject.get('key1').should eq('value1')
216
- subject.get('key2').should eq('value2')
215
+ expect(subject.get('key1')).to eq('value1')
216
+ expect(subject.get('key2')).to eq('value2')
217
217
  end
218
218
 
219
219
  it 'should set multiple keys to multiple values with a hash, only if none of the keys exist' do
220
- subject.mapped_msetnx(key1: 'value1', key2: 'value2').should be_true
221
- subject.mapped_msetnx(key1: 'value3', key2: 'value4').should be_false
220
+ expect(subject.mapped_msetnx(key1: 'value1', key2: 'value2')).to be_truthy
221
+ expect(subject.mapped_msetnx(key1: 'value3', key2: 'value4')).to be_falsey
222
222
 
223
- subject.get('key1').should eq('value1')
224
- subject.get('key2').should eq('value2')
223
+ expect(subject.get('key1')).to eq('value1')
224
+ expect(subject.get('key2')).to eq('value2')
225
225
  end
226
226
 
227
227
  it 'should set the string value of a key' do
228
228
  subject.set('key1', '1')
229
229
 
230
- subject.get('key1').should eq('1')
230
+ expect(subject.get('key1')).to eq('1')
231
231
  end
232
232
 
233
233
  it 'should sets or clears the bit at offset in the string value stored at key' do
234
234
  subject.set('key1', 'abc')
235
235
  subject.setbit('key1', 11, 1)
236
236
 
237
- subject.get('key1').should eq('arc')
237
+ expect(subject.get('key1')).to eq('arc')
238
238
  end
239
239
 
240
240
  it 'should set the value and expiration of a key' do
241
241
  subject.setex('key1', 30, 'value1')
242
242
 
243
- subject.get('key1').should eq('value1')
244
- subject.ttl('key1').should eq(30)
243
+ expect(subject.get('key1')).to eq('value1')
244
+ expect(subject.ttl('key1')).to eq(30)
245
245
  end
246
246
 
247
247
  it 'should set the value of a key, only if the key does not exist' do
@@ -249,20 +249,20 @@ shared_examples 'strings' do
249
249
  subject.setnx('key1', 'new value')
250
250
  subject.setnx('key2', 'another value')
251
251
 
252
- subject.get('key1').should eq('test value')
253
- subject.get('key2').should eq('another value')
252
+ expect(subject.get('key1')).to eq('test value')
253
+ expect(subject.get('key2')).to eq('another value')
254
254
  end
255
255
 
256
256
  it 'should overwrite part of a string at key starting at the specified offset' do
257
257
  subject.set('key1', 'Hello World')
258
258
  subject.setrange('key1', 6, 'Redis')
259
259
 
260
- subject.get('key1').should eq('Hello Redis')
260
+ expect(subject.get('key1')).to eq('Hello Redis')
261
261
  end
262
262
 
263
263
  it 'should get the length of the value stored in a key' do
264
264
  subject.set('key1', 'abc')
265
265
 
266
- subject.strlen('key1').should eq(3)
266
+ expect(subject.strlen('key1')).to eq(3)
267
267
  end
268
268
  end
@@ -1,19 +1,72 @@
1
1
  shared_examples 'transactions' do
2
- it 'should mark the start of a transaction block' do
3
- transaction = subject.multi do
4
- subject.set('key1', '1')
5
- subject.set('key2', '2')
6
- subject.mget('key1', 'key2')
2
+ context '#multi' do
3
+ it "should respond with 'OK'" do
4
+ expect(subject.multi).to eq('OK')
7
5
  end
8
6
 
9
- transaction.should eq(['OK', 'OK', ['1', '2']])
7
+ it "should forbid nesting" do
8
+ subject.multi
9
+ expect{subject.multi}.to raise_error(Redis::CommandError)
10
+ end
11
+
12
+ it "should mark the start of a transaction block" do
13
+ transaction = subject.multi do |multi|
14
+ multi.set('key1', '1')
15
+ multi.set('key2', '2')
16
+ multi.mget('key1', 'key2')
17
+ end
18
+
19
+ expect(transaction).to eq(['OK', 'OK', ['1', '2']])
20
+ end
21
+ end
22
+
23
+ context '#discard' do
24
+ it "should responde with 'OK' after #multi" do
25
+ subject.multi
26
+ expect(subject.discard).to eq('OK')
27
+ end
28
+
29
+ it "can't be run outside of #multi/#exec" do
30
+ expect{subject.discard}.to raise_error(Redis::CommandError)
31
+ end
32
+ end
33
+
34
+ context '#exec' do
35
+ it "can't be run outside of #multi" do
36
+ expect{subject.exec}.to raise_error(Redis::CommandError)
37
+ end
10
38
  end
11
39
 
12
- it 'should execute all command after multi' do
13
- subject.multi
14
- subject.set('key1', '1')
15
- subject.set('key2', '2')
16
- subject.mget('key1', 'key2')
17
- subject.exec.should be == ['OK', 'OK', ['1', '2']]
40
+ context 'saving up commands for later' do
41
+ before(:each) do
42
+ subject.multi
43
+ end
44
+
45
+ let(:string) { 'fake-redis-test:string' }
46
+ let(:list) { 'fake-redis-test:list' }
47
+
48
+ it "makes commands respond with 'QUEUED'" do
49
+ expect(subject.set(string, 'string')).to eq('QUEUED')
50
+ expect(subject.lpush(list, 'list')).to eq('QUEUED')
51
+ end
52
+
53
+ it "gives you the commands' responses when you call #exec" do
54
+ subject.set(string, 'string')
55
+ subject.lpush(list, 'list')
56
+ subject.lpush(list, 'list')
57
+
58
+ expect(subject.exec).to eq(['OK', 1, 2])
59
+ end
60
+
61
+ it "does not raise exceptions, but rather puts them in #exec's response" do
62
+ subject.set(string, 'string')
63
+ subject.lpush(string, 'oops!')
64
+ subject.lpush(list, 'list')
65
+
66
+ responses = subject.exec
67
+ expect(responses[0]).to eq('OK')
68
+ expect(responses[1]).to be_a(RuntimeError)
69
+ expect(responses[2]).to eq(1)
70
+ end
18
71
  end
19
72
  end
@@ -1,9 +1,9 @@
1
1
  shared_examples 'upcase method names' do
2
2
  it '#ZCOUNT' do
3
- subject.ZCOUNT('key', 2, 3).should eq(subject.zcount('key', 2, 3))
3
+ expect(subject.ZCOUNT('key', 2, 3)).to eq(subject.zcount('key', 2, 3))
4
4
  end
5
5
 
6
6
  it '#ZSCORE' do
7
- subject.ZSCORE('key', 2).should eq(subject.zscore('key', 2))
7
+ expect(subject.ZSCORE('key', 2)).to eq(subject.zscore('key', 2))
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rediska
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonid Beder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-08 00:00:00.000000000 Z
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '2.14'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '2.14'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: coveralls
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: |-
@@ -75,23 +75,26 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - .gitignore
79
- - .rspec
80
- - .travis.yml
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
81
  - Gemfile
82
82
  - Gemfile.lock
83
83
  - LICENSE
84
84
  - README.md
85
85
  - Rakefile
86
86
  - lib/rediska.rb
87
+ - lib/rediska/command_executor.rb
87
88
  - lib/rediska/configuration.rb
88
89
  - lib/rediska/connection.rb
89
90
  - lib/rediska/databases/expiring.rb
90
91
  - lib/rediska/databases/memory.rb
91
92
  - lib/rediska/databases/pstore.rb
92
93
  - lib/rediska/driver.rb
94
+ - lib/rediska/sort_method.rb
93
95
  - lib/rediska/sorted_set_argument_handler.rb
94
96
  - lib/rediska/sorted_set_store.rb
97
+ - lib/rediska/transaction_commands.rb
95
98
  - lib/rediska/version.rb
96
99
  - lib/rediska/zset.rb
97
100
  - rediska.gemspec
@@ -105,6 +108,7 @@ files:
105
108
  - spec/support/lists.rb
106
109
  - spec/support/server.rb
107
110
  - spec/support/sets.rb
111
+ - spec/support/sorted_method.rb
108
112
  - spec/support/sorted_sets.rb
109
113
  - spec/support/strings.rb
110
114
  - spec/support/transactions.rb
@@ -119,12 +123,12 @@ require_paths:
119
123
  - lib
120
124
  required_ruby_version: !ruby/object:Gem::Requirement
121
125
  requirements:
122
- - - '>='
126
+ - - ">="
123
127
  - !ruby/object:Gem::Version
124
128
  version: '0'
125
129
  required_rubygems_version: !ruby/object:Gem::Requirement
126
130
  requirements:
127
- - - '>='
131
+ - - ">="
128
132
  - !ruby/object:Gem::Version
129
133
  version: '0'
130
134
  requirements: []
@@ -144,6 +148,7 @@ test_files:
144
148
  - spec/support/lists.rb
145
149
  - spec/support/server.rb
146
150
  - spec/support/sets.rb
151
+ - spec/support/sorted_method.rb
147
152
  - spec/support/sorted_sets.rb
148
153
  - spec/support/strings.rb
149
154
  - spec/support/transactions.rb