rediska 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/lib/rediska/driver.rb +37 -1
- data/lib/rediska/version.rb +1 -1
- data/spec/redis_spec.rb +1 -1
- data/spec/support/hashes.rb +49 -0
- data/spec/support/lists.rb +5 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92a517169e6ce339fc0dd41bb2a3bc14ae34968e
|
4
|
+
data.tar.gz: 1cf4658e43eea53a54c3105a4b3cc829a2d22fdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e98bc067fa8f7e0b3a46a03833efeaec2a9c2f01705d30cec74dcf1c8ad738f179b3c9fc28efbdafabadea5b4f2f76b8089e0dd91abc7549664fd3f2d8a7f2ba
|
7
|
+
data.tar.gz: f2c501f284dabc099cbeb65f2805e1e2487fe163a25f2d67417e806e2809079ed028bb16660a457e5155aff5e2265c110d3b0a98eaebab4e2e19736f5cae4a8e
|
data/.travis.yml
CHANGED
data/lib/rediska/driver.rb
CHANGED
@@ -198,6 +198,42 @@ module Rediska
|
|
198
198
|
data[key].keys
|
199
199
|
end
|
200
200
|
|
201
|
+
def hscan(key, start_cursor, *args)
|
202
|
+
data_type_check(key, Hash)
|
203
|
+
return ['0', []] unless data[key]
|
204
|
+
|
205
|
+
match = '*'
|
206
|
+
count = 10
|
207
|
+
|
208
|
+
raise_argument_error('hscan') if args.size.odd?
|
209
|
+
|
210
|
+
if idx = args.index('MATCH')
|
211
|
+
match = args[idx + 1]
|
212
|
+
end
|
213
|
+
|
214
|
+
if idx = args.index('COUNT')
|
215
|
+
count = args[idx + 1]
|
216
|
+
end
|
217
|
+
|
218
|
+
start_cursor = start_cursor.to_i
|
219
|
+
|
220
|
+
cursor = start_cursor
|
221
|
+
next_keys = []
|
222
|
+
|
223
|
+
if start_cursor + count >= data[key].length
|
224
|
+
next_keys = (data[key].to_a)[start_cursor..-1]
|
225
|
+
cursor = 0
|
226
|
+
else
|
227
|
+
cursor = start_cursor + count
|
228
|
+
next_keys = (data[key].to_a)[start_cursor..cursor-1]
|
229
|
+
end
|
230
|
+
|
231
|
+
filtered_next_keys = next_keys.select{|k,v| File.fnmatch(match, k)}
|
232
|
+
result = filtered_next_keys.flatten.map(&:to_s)
|
233
|
+
|
234
|
+
return ["#{cursor}", result]
|
235
|
+
end
|
236
|
+
|
201
237
|
def keys(pattern = '*')
|
202
238
|
data.keys.select { |key| File.fnmatch(pattern, key) }
|
203
239
|
end
|
@@ -281,7 +317,7 @@ module Rediska
|
|
281
317
|
|
282
318
|
def lrem(key, count, value)
|
283
319
|
data_type_check(key, Array)
|
284
|
-
return unless data[key]
|
320
|
+
return 0 unless data[key]
|
285
321
|
old_size = data[key].size
|
286
322
|
diff =
|
287
323
|
if count == 0
|
data/lib/rediska/version.rb
CHANGED
data/spec/redis_spec.rb
CHANGED
data/spec/support/hashes.rb
CHANGED
@@ -210,4 +210,53 @@ shared_examples 'hashes' do
|
|
210
210
|
subject.hset('key1', 1, 0)
|
211
211
|
expect(subject.hincrby('key1', 1, 1)).to eq(1)
|
212
212
|
end
|
213
|
+
|
214
|
+
describe "#hscan" do
|
215
|
+
it 'with no arguments and few items, returns all items' do
|
216
|
+
subject.hmset('hash', 'name', 'Jack', 'age', '33')
|
217
|
+
result = subject.hscan('hash', 0)
|
218
|
+
|
219
|
+
expect(result[0]).to eq('0')
|
220
|
+
expect(result[1]).to eq([['name', 'Jack'], ['age', '33']])
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'with a count should return that number of members or more' do
|
224
|
+
subject.hmset('hash','a', '1', 'b', '2', 'c', '3', 'd', '4', 'e', '5', 'f', '6', 'g', '7')
|
225
|
+
result = subject.hscan('hash', 0, count: 3)
|
226
|
+
expect(result[0]).to eq('3')
|
227
|
+
expect(result[1]).to eq([
|
228
|
+
['a', '1'],
|
229
|
+
['b', '2'],
|
230
|
+
['c', '3'],
|
231
|
+
])
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'returns items starting at the provided cursor' do
|
235
|
+
subject.hmset('hash', 'a', '1', 'b', '2', 'c', '3', 'd', '4', 'e', '5', 'f', '6', 'g', '7')
|
236
|
+
result = subject.hscan('hash', 2, count: 3)
|
237
|
+
expect(result[0]).to eq('5')
|
238
|
+
expect(result[1]).to eq([
|
239
|
+
['c', '3'],
|
240
|
+
['d', '4'],
|
241
|
+
['e', '5']
|
242
|
+
])
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'with match, returns items matching the given pattern' do
|
246
|
+
subject.hmset('hash', 'aa', '1', 'b', '2', 'cc', '3', 'd', '4', 'ee', '5', 'f', '6', 'gg', '7')
|
247
|
+
result = subject.hscan('hash', 2, count: 3, match: '??')
|
248
|
+
expect(result[0]).to eq('5')
|
249
|
+
expect(result[1]).to eq([
|
250
|
+
['cc', '3'],
|
251
|
+
['ee', '5']
|
252
|
+
])
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'returns an empty result if the key is not found' do
|
256
|
+
result = subject.hscan('hash', 0)
|
257
|
+
|
258
|
+
expect(result[0]).to eq('0')
|
259
|
+
expect(result[1]).to eq([])
|
260
|
+
end
|
261
|
+
end
|
213
262
|
end
|
data/spec/support/lists.rb
CHANGED
@@ -89,6 +89,11 @@ shared_examples 'lists' do
|
|
89
89
|
expect(subject.llen('key1')).to eq(2)
|
90
90
|
end
|
91
91
|
|
92
|
+
it 'should return 0 if key does not map to a list' do
|
93
|
+
expect(subject.exists('nonexistant')).to eq(false)
|
94
|
+
expect(subject.lrem('nonexistant', 0, 'value')).to eq(0)
|
95
|
+
end
|
96
|
+
|
92
97
|
it "should remove list's key when list is empty" do
|
93
98
|
subject.rpush('key1', 'v1')
|
94
99
|
subject.rpush('key1', 'v2')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rediska
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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: 2015-07
|
11
|
+
date: 2015-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.4.
|
153
|
+
rubygems_version: 2.4.8
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: A light-weighted redis driver for testing, development, and minimal environments
|