rediska 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f86c134332ab9cf5217916caadf33c173e95c2ba
4
- data.tar.gz: 6237f5b3dbc747d40294e4e93ba933afd687b78c
3
+ metadata.gz: 9b925c99be9718a0a3e6d13337995347425b9d77
4
+ data.tar.gz: 2b5a2d0e166f101fa7bea426b65c19386c9fd3e7
5
5
  SHA512:
6
- metadata.gz: c73bfe01ede94fdaa21c058d20723c19367c4cd23ecb3a4d30032e758c395def2eabe115f00927aede66f835a9b448b5708f6ad7067dc671182adc390173b2cd
7
- data.tar.gz: d17031c7ac9a702dfce106bbceaa777bd1a7a4dc94c889e35fb8f65a32222b761670984bcb785a3d993543000a8646721c2b7988c560efb03fc92a614aa6a33a
6
+ metadata.gz: 4a74e9bfc2f2ec3d2be3ab702ab94ca205d01b62b825f9850b3c967a32afc42ac97bdb51632b49c63b9b15c075d92d3a9b61b49a553af41afb3a144e4a11661e
7
+ data.tar.gz: 8ebe0205e528f90c9c980bb87b90ae9d17f692b70b3e63bc795f0b4dd94189d6094fda19368e639f8af0df35fdf43f2a367bd477e0e95ac521a5e54520c2b2b0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rediska (0.0.8)
4
+ rediska (0.0.9)
5
5
  redis (~> 3.0.0)
6
6
 
7
7
  GEM
@@ -595,7 +595,7 @@ module Rediska
595
595
  old_val = data[key] ? data[key].unpack('B*')[0].split('') : []
596
596
  size_increment = [((offset/8)+1)*8-old_val.length, 0].max
597
597
  old_val += Array.new(size_increment).map{'0'}
598
- original_val = old_val[offset]
598
+ original_val = old_val[offset].to_i
599
599
  old_val[offset] = bit.to_s
600
600
  new_val = ''
601
601
  old_val.each_slice(8){|b| new_val = new_val + b.join('').to_i(2).chr }
@@ -704,6 +704,39 @@ module Rediska
704
704
  'OK'
705
705
  end
706
706
 
707
+ def scan(start_cursor, *args)
708
+ match = '*'
709
+ count = 10
710
+
711
+ if args.size.odd?
712
+ raise_argument_error('scan')
713
+ end
714
+
715
+ if idx = args.index('MATCH')
716
+ match = args[idx + 1]
717
+ end
718
+
719
+ if idx = args.index('COUNT')
720
+ count = args[idx + 1]
721
+ end
722
+
723
+ start_cursor = start_cursor.to_i
724
+ data_type_check(start_cursor, Fixnum)
725
+
726
+ cursor = start_cursor
727
+ next_keys = []
728
+
729
+ if start_cursor + count >= data.length
730
+ next_keys = keys(match)[start_cursor..-1]
731
+ cursor = 0
732
+ else
733
+ cursor = start_cursor + 10
734
+ next_keys = keys(match)[start_cursor..cursor]
735
+ end
736
+
737
+ return "#{cursor}", next_keys
738
+ end
739
+
707
740
  def zadd(key, *args)
708
741
  if !args.first.is_a?(Array)
709
742
  if args.size < 2
@@ -1,3 +1,3 @@
1
1
  module Rediska
2
- VERSION = '0.0.8'.freeze
2
+ VERSION = '0.0.9'.freeze
3
3
  end
@@ -279,4 +279,51 @@ shared_examples 'keys' do
279
279
  subject.select(0)
280
280
  subject.get('key1').should eq('1')
281
281
  end
282
+
283
+ it 'should scan all keys in the database' do
284
+ 100.times do |x|
285
+ subject.set("key#{x}", "#{x}")
286
+ end
287
+
288
+ cursor = 0
289
+ all_keys = []
290
+ loop do
291
+ cursor, keys = subject.scan(cursor)
292
+ all_keys += keys
293
+ break if cursor == '0'
294
+ end
295
+
296
+ all_keys.uniq.should have(100).items
297
+ all_keys[0].should =~ /key\d+/
298
+ end
299
+
300
+ it "should match keys to a pattern when scanning" do
301
+ 50.times do |x|
302
+ subject.set("key#{x}", "#{x}")
303
+ end
304
+
305
+ subject.set('miss_me', 1)
306
+ subject.set('pass_me', 2)
307
+
308
+ cursor = 0
309
+ all_keys = []
310
+ loop do
311
+ cursor, keys = subject.scan(cursor, match: 'key*')
312
+ all_keys += keys
313
+ break if cursor == '0'
314
+ end
315
+
316
+ all_keys.uniq.should have(50).items
317
+ end
318
+
319
+ it 'should specify doing more work when scanning' do
320
+ 100.times do |x|
321
+ subject.set("key#{x}", "#{x}")
322
+ end
323
+
324
+ cursor, all_keys = subject.scan(cursor, count: 100)
325
+
326
+ cursor.should eq('0')
327
+ all_keys.uniq.should have(100).items
328
+ end
282
329
  end
@@ -41,6 +41,34 @@ shared_examples 'strings' do
41
41
  subject.getbit('key1', 10).should eq(1)
42
42
  end
43
43
 
44
+ context 'when a bit is previously set to 0' do
45
+ before do
46
+ subject.setbit('key1', 10, 0)
47
+ end
48
+
49
+ it 'setting it to 1 returns 0' do
50
+ subject.setbit('key1', 10, 1).should eq(0)
51
+ end
52
+
53
+ it 'setting it to 0 returns 0' do
54
+ subject.setbit('key1', 10, 0).should eq(0)
55
+ end
56
+ end
57
+
58
+ context 'when a bit is previously set to 1' do
59
+ before do
60
+ subject.setbit('key1', 10, 1)
61
+ end
62
+
63
+ it 'setting it to 0 returns 1' do
64
+ subject.setbit('key1', 10, 0).should eq(1)
65
+ end
66
+
67
+ it 'setting it to 1 returns 1' do
68
+ subject.setbit('key1', 10, 1).should eq(1)
69
+ end
70
+ end
71
+
44
72
  it 'should get a substring of the string stored at a key' do
45
73
  subject.set('key1', 'This a message')
46
74
 
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.0.8
4
+ version: 0.0.9
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-04-02 00:00:00.000000000 Z
11
+ date: 2014-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis