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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cac5ab0cf5c9ba0846696f9f0bc11d6a9d576e98
4
- data.tar.gz: 25fa085315e109766cae1a0ae5c938a74c1a04c7
3
+ metadata.gz: 86590f87e71e79ef8d9624662cd55130cc2df1fa
4
+ data.tar.gz: 2d597efe6a69febee382756b7ff31094b53b0ee8
5
5
  SHA512:
6
- metadata.gz: 27670128763f2c6c4a841af63b0346e7cd69b1d5b2b4db7dae2c36bff51c47e25baa895512ebfe5c006920ca82b7235b5d8d3d04ee13d87b2f2c31f31e5b53e9
7
- data.tar.gz: 93e4b593c02acd50548a7e26ab03b1f0280bf36c9d58147ebd8f6af1cbf3ab527ef672053ad96cd14feeeb34231b03375acd006c546e43af881ae81dc55e1fd1
6
+ metadata.gz: 76ef357352b0ca28da01edbdada2b8f6c9215b367c60ee9061c48a76043fda783aedbe8a5b8547d65c3c4db44ca4611b246e5f32af994532c0b07fef0460c72e
7
+ data.tar.gz: d5a0c5cbd82bc13f08cce191f3f13f3dba9608654593c0b071ddd0f902dfae884c1298dfa40041ea224f814da24f401f9a039f76fd4ae984b1468e589ff8c339
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rediska (0.1.6)
4
+ rediska (0.1.7)
5
5
  redis (>= 3)
6
6
 
7
7
  GEM
@@ -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]
@@ -1,3 +1,3 @@
1
1
  module Rediska
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.1.7'.freeze
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rediska
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonid Beder