redness 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
@@ -8,13 +8,23 @@ class TimedRedSet < RedSet
8
8
  precise_start = Precisionable.int_from_float(start)
9
9
 
10
10
  redis.execute_with_uncertainty([]) do
11
+ raw = redis.zrevrangebyscore(key, "+inf", precise_start, with_scores: options[:with_scores])
12
+
11
13
  if options[:upper] and options[:lower]
12
14
  lower = options[:lower].to_i
13
15
  upper = options[:upper].to_i
14
16
 
15
- redis.zrevrangebyscore(key, "+inf", precise_start)[lower..upper].map(&:to_i)
17
+ raw = raw[lower..upper]
18
+ end
19
+
20
+ if options[:with_scores]
21
+ result = {}
22
+ raw.each do |member, score|
23
+ result[member.to_i] = Time.at(Precisionable.float_from_int(score))
24
+ end
25
+ result
16
26
  else
17
- redis.zrevrangebyscore(key, "+inf", precise_start).map(&:to_i)
27
+ raw.map(&:to_i)
18
28
  end
19
29
  end
20
30
  end
@@ -1,4 +1,4 @@
1
1
  module Redness
2
- VERSION="0.2.0"
2
+ VERSION="0.2.1"
3
3
  MAJOR, MINOR, TINY = VERSION.split(".")
4
4
  end
@@ -54,6 +54,24 @@ describe TimedRedSet do
54
54
  TimedRedSet.since("somekey", 1.day.ago, :lower => 0, :upper => 1).should == [3,2]
55
55
  TimedRedSet.since("somekey", 1.day.ago, :lower => 1, :upper => 2).should == [2,1]
56
56
  end
57
+
58
+ it "returns an array of elements with timestamps if the with_scores option is true" do
59
+ Timecop.freeze(Time.at(1.5)) { TimedRedSet.add('somekey', 10) }
60
+ Timecop.freeze(Time.at(2.5)) { TimedRedSet.add('somekey', 20) }
61
+ Timecop.freeze(Time.at(3.5)) { TimedRedSet.add('somekey', 30) }
62
+
63
+ TimedRedSet.since('somekey', 2, :with_scores => true).should ==
64
+ {20 => Time.at(2.5), 30 => Time.at(3.5)}
65
+ end
66
+
67
+ it "supports using the :upper/:lower and :with_scores attributes together" do
68
+ Timecop.freeze(Time.at(1.5)) { TimedRedSet.add('somekey', 10) }
69
+ Timecop.freeze(Time.at(2.5)) { TimedRedSet.add('somekey', 20) }
70
+ Timecop.freeze(Time.at(3.5)) { TimedRedSet.add('somekey', 30) }
71
+
72
+ TimedRedSet.since('somekey', 2, :lower => 1, :upper => 1, :with_scores => true).should ==
73
+ {20 => Time.at(2.5)}
74
+ end
57
75
  end
58
76
 
59
77
  describe ".get_with_timestamps" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2013-03-04 00:00:00.000000000 Z
17
+ date: 2013-08-28 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: json
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  version: '0'
172
172
  requirements: []
173
173
  rubyforge_project:
174
- rubygems_version: 1.8.23
174
+ rubygems_version: 1.8.25
175
175
  signing_key:
176
176
  specification_version: 3
177
177
  summary: Helpful Ruby classes for improved Redis data structures