rediska 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ace76e76418b38e8b9b46fcdb5c4db0455e89c95
4
- data.tar.gz: 902e598e4cd72baae2e0f376edb6c9215a3873c3
3
+ metadata.gz: 92a517169e6ce339fc0dd41bb2a3bc14ae34968e
4
+ data.tar.gz: 1cf4658e43eea53a54c3105a4b3cc829a2d22fdb
5
5
  SHA512:
6
- metadata.gz: 19eb6136ff931a2cd42f2c71fd17ab6e83433822fcb7105c1993f30a1b39102e11fd04feded16da5a317abc294149f9c42c876461fe44b0f8bafda00856dd744
7
- data.tar.gz: 4393f6c7a5f98b32c8bb0a6432ed3248c702344cac9221fcc4c44b138a1ff1f1d433045d0e7a7ee2a888a2a61dff215db94fc03296f822d9b8c294df93058f25
6
+ metadata.gz: e98bc067fa8f7e0b3a46a03833efeaec2a9c2f01705d30cec74dcf1c8ad738f179b3c9fc28efbdafabadea5b4f2f76b8089e0dd91abc7549664fd3f2d8a7f2ba
7
+ data.tar.gz: f2c501f284dabc099cbeb65f2805e1e2487fe163a25f2d67417e806e2809079ed028bb16660a457e5155aff5e2265c110d3b0a98eaebab4e2e19736f5cae4a8e
@@ -10,6 +10,8 @@ rvm:
10
10
  - rbx-2
11
11
  gemfile:
12
12
  - Gemfile
13
+ services:
14
+ - redis-server
13
15
  matrix:
14
16
  allow_failures:
15
17
  - rvm: rbx-2
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rediska
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
@@ -46,7 +46,7 @@ describe 'Rediska' do
46
46
  end
47
47
  end
48
48
 
49
- pending 'real redis (interoperability)' do
49
+ context 'real redis (interoperability)' do
50
50
  before(:all) do
51
51
  Redis::Connection.drivers.pop
52
52
  end
@@ -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
@@ -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.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-31 00:00:00.000000000 Z
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.6
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