rediska 0.1.6 → 0.1.7
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/Gemfile.lock +1 -1
- data/lib/rediska/driver.rb +6 -0
- data/lib/rediska/version.rb +1 -1
- data/spec/support/strings.rb +26 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86590f87e71e79ef8d9624662cd55130cc2df1fa
|
4
|
+
data.tar.gz: 2d597efe6a69febee382756b7ff31094b53b0ee8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76ef357352b0ca28da01edbdada2b8f6c9215b367c60ee9061c48a76043fda783aedbe8a5b8547d65c3c4db44ca4611b246e5f32af994532c0b07fef0460c72e
|
7
|
+
data.tar.gz: d5a0c5cbd82bc13f08cce191f3f13f3dba9608654593c0b071ddd0f902dfae884c1298dfa40041ea224f814da24f401f9a039f76fd4ae984b1468e589ff8c339
|
data/Gemfile.lock
CHANGED
data/lib/rediska/driver.rb
CHANGED
@@ -94,6 +94,12 @@ module Rediska
|
|
94
94
|
data[key].unpack('B*')[0].split('')[offset].to_i
|
95
95
|
end
|
96
96
|
|
97
|
+
def bitcount(key, start_index = 0, end_index = -1)
|
98
|
+
return 0 unless data[key]
|
99
|
+
|
100
|
+
data[key][start_index..end_index].unpack('B*')[0].count('1')
|
101
|
+
end
|
102
|
+
|
97
103
|
def getrange(key, start, ending)
|
98
104
|
return unless data[key]
|
99
105
|
data[key][start..ending]
|
data/lib/rediska/version.rb
CHANGED
data/spec/support/strings.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
shared_examples 'strings' do
|
2
4
|
it 'should append a value to key' do
|
3
5
|
subject.set('key1', 'Hello')
|
@@ -265,4 +267,28 @@ shared_examples 'strings' do
|
|
265
267
|
|
266
268
|
expect(subject.strlen('key1')).to eq(3)
|
267
269
|
end
|
270
|
+
|
271
|
+
it "should return 0 bits when there's no key" do
|
272
|
+
expect(subject.bitcount('key1')).to eq(0)
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'should count the number of bits of a string' do
|
276
|
+
subject.set('key1', 'foobar')
|
277
|
+
|
278
|
+
expect(subject.bitcount('key1')).to eq(26)
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'should count correctly with UTF-8 strings' do
|
282
|
+
subject.set('key1', '判')
|
283
|
+
|
284
|
+
expect(subject.bitcount('key1')).to eq(10)
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'should count the number of bits of a string given a range' do
|
288
|
+
subject.set('key1', 'foobar')
|
289
|
+
|
290
|
+
expect(subject.bitcount('key1', 0, 0)).to eq(4)
|
291
|
+
expect(subject.bitcount('key1', 1, 1)).to eq(6)
|
292
|
+
expect(subject.bitcount('key1', 0, 1)).to eq(10)
|
293
|
+
end
|
268
294
|
end
|