rediska 0.0.2
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.
- data/.gitignore +19 -0
- data/.rspec +3 -0
- data/.travis.yml +4 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +70 -0
- data/LICENSE +20 -0
- data/README.md +95 -0
- data/Rakefile +7 -0
- data/lib/rediska/configuration.rb +11 -0
- data/lib/rediska/connection.rb +67 -0
- data/lib/rediska/databases/expiring.rb +87 -0
- data/lib/rediska/databases/memory.rb +21 -0
- data/lib/rediska/databases/pstore.rb +72 -0
- data/lib/rediska/driver.rb +910 -0
- data/lib/rediska/sorted_set_argument_handler.rb +54 -0
- data/lib/rediska/sorted_set_store.rb +80 -0
- data/lib/rediska/version.rb +3 -0
- data/lib/rediska/zset.rb +26 -0
- data/lib/rediska.rb +18 -0
- data/rediska.gemspec +26 -0
- data/spec/redis_spec.rb +64 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/compatibility.rb +7 -0
- data/spec/support/connection.rb +65 -0
- data/spec/support/hashes.rb +189 -0
- data/spec/support/keys.rb +261 -0
- data/spec/support/lists.rb +196 -0
- data/spec/support/server.rb +93 -0
- data/spec/support/sets.rb +175 -0
- data/spec/support/sorted_sets.rb +447 -0
- data/spec/support/strings.rb +240 -0
- data/spec/support/transactions.rb +11 -0
- data/spec/support/upcase_method_names.rb +9 -0
- metadata +174 -0
@@ -0,0 +1,240 @@
|
|
1
|
+
shared_examples 'strings' do
|
2
|
+
it 'should append a value to key' do
|
3
|
+
subject.set('key1', 'Hello')
|
4
|
+
subject.append('key1', ' World')
|
5
|
+
|
6
|
+
subject.get('key1').should eq('Hello World')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should decrement the integer value of a key by one' do
|
10
|
+
subject.set('counter', '1')
|
11
|
+
subject.decr('counter')
|
12
|
+
|
13
|
+
subject.get('counter').should eq('0')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should decrement the integer value of a key by the given number' do
|
17
|
+
subject.set('counter', '10')
|
18
|
+
subject.decrby('counter', '5')
|
19
|
+
|
20
|
+
subject.get('counter').should eq('5')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should get the value of a key' do
|
24
|
+
subject.get('key2').should be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should returns the bit value at offset in the string value stored at key' do
|
28
|
+
subject.set('key1', 'a')
|
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)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should allow direct bit manipulation even if the string is not set' do
|
40
|
+
subject.setbit('key1', 10, 1)
|
41
|
+
subject.getbit('key1', 10).should eq(1)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should get a substring of the string stored at a key' do
|
45
|
+
subject.set('key1', 'This a message')
|
46
|
+
|
47
|
+
subject.getrange('key1', 0, 3).should eq('This')
|
48
|
+
subject.substr('key1', 0, 3).should eq('This')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should set the string value of a key and return its old value' do
|
52
|
+
subject.set('key1','value1')
|
53
|
+
|
54
|
+
subject.getset('key1', 'value2').should eq('value1')
|
55
|
+
subject.get('key1').should eq('value2')
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should return nil for #getset if the key does not exist when setting' do
|
59
|
+
subject.getset('key1', 'value1').should be_nil
|
60
|
+
subject.get('key1').should eq('value1')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should increment the integer value of a key by one' do
|
64
|
+
subject.set('counter', '1')
|
65
|
+
subject.incr('counter').should eq(2)
|
66
|
+
|
67
|
+
subject.get('counter').should eq('2')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should not change the expire value of the key during incr' do
|
71
|
+
subject.set('counter', '1')
|
72
|
+
subject.expire('counter', 600).should be_true
|
73
|
+
|
74
|
+
subject.ttl('counter').should eq(600)
|
75
|
+
subject.incr('counter').should eq(2)
|
76
|
+
subject.ttl('counter').should be_within(10).of(600)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should decrement the integer value of a key by one' do
|
80
|
+
subject.set('counter', '1')
|
81
|
+
subject.decr('counter').should eq(0)
|
82
|
+
|
83
|
+
subject.get('counter').should eq('0')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should not change the expire value of the key during decr' do
|
87
|
+
subject.set('counter', '2')
|
88
|
+
subject.expire('counter', 600).should be_true
|
89
|
+
|
90
|
+
subject.ttl('counter').should eq(600)
|
91
|
+
subject.decr('counter').should eq(1)
|
92
|
+
subject.ttl('counter').should be_within(10).of(600)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should increment the integer value of a key by the given number' do
|
96
|
+
subject.set('counter', '10')
|
97
|
+
subject.incrby('counter', '5').should eq(15)
|
98
|
+
subject.incrby('counter', 2).should eq(17)
|
99
|
+
subject.get('counter').should eq('17')
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should not change the expire value of the key during incrby' do
|
103
|
+
subject.set('counter', '1')
|
104
|
+
subject.expire('counter', 600).should be_true
|
105
|
+
|
106
|
+
subject.ttl('counter').should eq(600)
|
107
|
+
subject.incrby('counter', '5').should eq(6)
|
108
|
+
subject.ttl('counter').should be_within(10).of(600)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should decrement the integer value of a key by the given number' do
|
112
|
+
subject.set('counter', '10')
|
113
|
+
subject.decrby('counter', '5').should eq(5)
|
114
|
+
subject.decrby('counter', 2).should eq(3)
|
115
|
+
subject.get('counter').should eq('3')
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should not change the expire value of the key during decrby' do
|
119
|
+
subject.set('counter', '8')
|
120
|
+
subject.expire('counter', 600).should be_true
|
121
|
+
|
122
|
+
subject.ttl('counter').should eq(600)
|
123
|
+
subject.decrby('counter', '3').should eq(5)
|
124
|
+
subject.ttl('counter').should be_within(10).of(600)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should get the values of all the given keys' do
|
128
|
+
subject.set('key1', 'value1')
|
129
|
+
subject.set('key2', 'value2')
|
130
|
+
subject.set('key3', 'value3')
|
131
|
+
|
132
|
+
subject.mget('key1', 'key2', 'key3').should eq(['value1', 'value2', 'value3'])
|
133
|
+
subject.mget(['key1', 'key2', 'key3']).should eq(['value1', 'value2', 'value3'])
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'returns nil for non existent keys' do
|
137
|
+
subject.set('key1', 'value1')
|
138
|
+
subject.set('key3', 'value3')
|
139
|
+
|
140
|
+
subject.mget('key1', 'key2', 'key3', 'key4').should eq(['value1', nil, 'value3', nil])
|
141
|
+
subject.mget(['key1', 'key2', 'key3', 'key4']).should eq(['value1', nil, 'value3', nil])
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'raises an argument error when not passed any fields' do
|
145
|
+
subject.set('key3', 'value3')
|
146
|
+
|
147
|
+
expect {
|
148
|
+
subject.mget
|
149
|
+
}.to raise_error(Redis::CommandError)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should set multiple keys to multiple values' do
|
153
|
+
subject.mset(:key1, 'value1', :key2, 'value2')
|
154
|
+
|
155
|
+
subject.get('key1').should eq('value1')
|
156
|
+
subject.get('key2').should eq('value2')
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should raise error if command arguments count is wrong' do
|
160
|
+
expect {
|
161
|
+
subject.mset
|
162
|
+
}.to raise_error(Redis::CommandError)
|
163
|
+
|
164
|
+
expect {
|
165
|
+
subject.mset(:key1)
|
166
|
+
}.to raise_error(Redis::CommandError)
|
167
|
+
|
168
|
+
expect {
|
169
|
+
subject.mset(:key1, 'value', :key2)
|
170
|
+
}.to raise_error(Redis::CommandError)
|
171
|
+
|
172
|
+
subject.get('key1').should be_nil
|
173
|
+
subject.get('key2').should be_nil
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should set multiple keys to multiple values, only if none of the keys exist' do
|
177
|
+
subject.msetnx(:key1, 'value1', :key2, 'value2').should be_true
|
178
|
+
subject.msetnx(:key1, 'value3', :key2, 'value4').should be_false
|
179
|
+
|
180
|
+
subject.get('key1').should eq('value1')
|
181
|
+
subject.get('key2').should eq('value2')
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should set multiple keys to multiple values with a hash' do
|
185
|
+
subject.mapped_mset(key1: 'value1', key2: 'value2')
|
186
|
+
|
187
|
+
subject.get('key1').should eq('value1')
|
188
|
+
subject.get('key2').should eq('value2')
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'should set multiple keys to multiple values with a hash, only if none of the keys exist' do
|
192
|
+
subject.mapped_msetnx(key1: 'value1', key2: 'value2').should be_true
|
193
|
+
subject.mapped_msetnx(key1: 'value3', key2: 'value4').should be_false
|
194
|
+
|
195
|
+
subject.get('key1').should eq('value1')
|
196
|
+
subject.get('key2').should eq('value2')
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should set the string value of a key' do
|
200
|
+
subject.set('key1', '1')
|
201
|
+
|
202
|
+
subject.get('key1').should eq('1')
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should sets or clears the bit at offset in the string value stored at key' do
|
206
|
+
subject.set('key1', 'abc')
|
207
|
+
subject.setbit('key1', 11, 1)
|
208
|
+
|
209
|
+
subject.get('key1').should eq('arc')
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'should set the value and expiration of a key' do
|
213
|
+
subject.setex('key1', 30, 'value1')
|
214
|
+
|
215
|
+
subject.get('key1').should eq('value1')
|
216
|
+
subject.ttl('key1').should eq(30)
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'should set the value of a key, only if the key does not exist' do
|
220
|
+
subject.set('key1', 'test value')
|
221
|
+
subject.setnx('key1', 'new value')
|
222
|
+
subject.setnx('key2', 'another value')
|
223
|
+
|
224
|
+
subject.get('key1').should eq('test value')
|
225
|
+
subject.get('key2').should eq('another value')
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'should overwrite part of a string at key starting at the specified offset' do
|
229
|
+
subject.set('key1', 'Hello World')
|
230
|
+
subject.setrange('key1', 6, 'Redis')
|
231
|
+
|
232
|
+
subject.get('key1').should eq('Hello Redis')
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'should get the length of the value stored in a key' do
|
236
|
+
subject.set('key1', 'abc')
|
237
|
+
|
238
|
+
subject.strlen('key1').should eq(3)
|
239
|
+
end
|
240
|
+
end
|
@@ -0,0 +1,11 @@
|
|
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')
|
7
|
+
end
|
8
|
+
|
9
|
+
transaction.should eq(['OK', 'OK', ['1', '2']])
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rediska
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Leonid Beder
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redis
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.14'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.14'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: coveralls
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: pry-debugger
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: ! "A light-weighted redis driver for testing, development, and minimal
|
95
|
+
environments,\n which supports various data storage strategies"
|
96
|
+
email:
|
97
|
+
- leonid.beder@gmail.com
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- .rspec
|
104
|
+
- .travis.yml
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/rediska.rb
|
111
|
+
- lib/rediska/configuration.rb
|
112
|
+
- lib/rediska/connection.rb
|
113
|
+
- lib/rediska/databases/expiring.rb
|
114
|
+
- lib/rediska/databases/memory.rb
|
115
|
+
- lib/rediska/databases/pstore.rb
|
116
|
+
- lib/rediska/driver.rb
|
117
|
+
- lib/rediska/sorted_set_argument_handler.rb
|
118
|
+
- lib/rediska/sorted_set_store.rb
|
119
|
+
- lib/rediska/version.rb
|
120
|
+
- lib/rediska/zset.rb
|
121
|
+
- rediska.gemspec
|
122
|
+
- spec/redis_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
- spec/support/compatibility.rb
|
125
|
+
- spec/support/connection.rb
|
126
|
+
- spec/support/hashes.rb
|
127
|
+
- spec/support/keys.rb
|
128
|
+
- spec/support/lists.rb
|
129
|
+
- spec/support/server.rb
|
130
|
+
- spec/support/sets.rb
|
131
|
+
- spec/support/sorted_sets.rb
|
132
|
+
- spec/support/strings.rb
|
133
|
+
- spec/support/transactions.rb
|
134
|
+
- spec/support/upcase_method_names.rb
|
135
|
+
homepage: https://github.com/lbeder/rediska
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 1.8.25
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: A light-weighted redis driver for testing, development, and minimal environments
|
160
|
+
test_files:
|
161
|
+
- spec/redis_spec.rb
|
162
|
+
- spec/spec_helper.rb
|
163
|
+
- spec/support/compatibility.rb
|
164
|
+
- spec/support/connection.rb
|
165
|
+
- spec/support/hashes.rb
|
166
|
+
- spec/support/keys.rb
|
167
|
+
- spec/support/lists.rb
|
168
|
+
- spec/support/server.rb
|
169
|
+
- spec/support/sets.rb
|
170
|
+
- spec/support/sorted_sets.rb
|
171
|
+
- spec/support/strings.rb
|
172
|
+
- spec/support/transactions.rb
|
173
|
+
- spec/support/upcase_method_names.rb
|
174
|
+
has_rdoc:
|