rediska 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rediska/version.rb +1 -1
- data/lib/rediska/zset.rb +7 -5
- data/spec/support/sorted_sets.rb +5 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d99bbf132cfad70e1ef799c197afc9017613ea4
|
4
|
+
data.tar.gz: eabb66ff059f336bfa134bf56eddd9cb55aee205
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 597a9fe6a0368312924a1e366f653c215f2bda9534701e0961557230b8d884ec23744b7dd9969043bf9e8a97f792a746922e4605d73230ebef41380891aa18fc
|
7
|
+
data.tar.gz: 6f9defadb0d09a0fb19cf8dfb2cde86828b26d65456af394a88956f1cf292c3faa0be0d04fec475c2f4a67391f0c9487281efec83d914520a43ce6684b95e028
|
data/Gemfile.lock
CHANGED
data/lib/rediska/version.rb
CHANGED
data/lib/rediska/zset.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
module Rediska
|
2
2
|
class ZSet < Hash
|
3
3
|
def []=(key, val)
|
4
|
-
super(key,
|
4
|
+
super(key, _floatify(val))
|
5
5
|
end
|
6
6
|
|
7
7
|
def increment(key, val)
|
8
|
-
self[key] +=
|
8
|
+
self[key] += _floatify(val)
|
9
9
|
end
|
10
10
|
|
11
11
|
def select_by_score(min, max)
|
12
|
-
min =
|
13
|
-
max =
|
12
|
+
min = _floatify(min, true)
|
13
|
+
max = _floatify(max, false)
|
14
14
|
reject {|_,v| v < min || v > max }
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
|
-
def
|
18
|
+
def _floatify(str, increment = true)
|
19
19
|
if inf = str.to_s.match(/^([+-])?inf/i)
|
20
20
|
(inf[1] == '-' ? -1.0 : 1.0) / 0.0
|
21
|
+
elsif ((number = str.to_s.match(/^\((\d+)/i)))
|
22
|
+
number[1].to_i + (increment ? 1 : -1)
|
21
23
|
else
|
22
24
|
Float(str)
|
23
25
|
end
|
data/spec/support/sorted_sets.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
shared_examples 'sorted sets' do
|
2
2
|
let(:infinity) { 1.0 / 0.0 }
|
3
3
|
|
4
|
-
before(:each) do
|
5
|
-
subject = Redis.new
|
6
|
-
end
|
7
|
-
|
8
4
|
it 'should add a member to a sorted set, or update its score if it already exists' do
|
9
5
|
subject.zadd('key', 1, 'val').should be_true
|
10
6
|
subject.zscore('key', 'val').should eq(1.0)
|
@@ -173,6 +169,9 @@ shared_examples 'sorted sets' do
|
|
173
169
|
|
174
170
|
subject.zrangebyscore('key', 0, 100).should eq(['one', 'two', 'three'])
|
175
171
|
subject.zrangebyscore('key', 1, 2).should eq(['one', 'two'])
|
172
|
+
subject.zrangebyscore('key', 1, '(2').should eq(['one'])
|
173
|
+
subject.zrangebyscore('key', '(1', 2).should eq(['two'])
|
174
|
+
subject.zrangebyscore('key', '(1', '(2').should eq([])
|
176
175
|
subject.zrangebyscore('key', 0, 100, with_scores: true).should eq([['one', 1], ['two', 2], ['three', 3]])
|
177
176
|
subject.zrangebyscore('key', 1, 2, with_scores: true).should eq([['one', 1], ['two', 2]])
|
178
177
|
subject.zrangebyscore('key', 0, 100, limit: [0, 1]).should eq(['one'])
|
@@ -181,6 +180,8 @@ shared_examples 'sorted sets' do
|
|
181
180
|
subject.zrangebyscore('key', '-inf', '+inf').should eq(['one', 'two', 'three'])
|
182
181
|
subject.zrangebyscore('key', 2, '+inf').should eq(['two', 'three'])
|
183
182
|
subject.zrangebyscore('key', '-inf', 2).should eq(['one', 'two'])
|
183
|
+
|
184
|
+
subject.zrangebyscore('badkey', 1, 2).should eq([])
|
184
185
|
end
|
185
186
|
|
186
187
|
it 'should return a reversed range of members in a sorted set, by score' do
|
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.
|
4
|
+
version: 0.0.10
|
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-
|
11
|
+
date: 2014-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|