Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
3  .gitignore
@@ -0,0 +1,3 @@
+cscope.*
+tags
+.rvmrc
View
2  Gemfile
@@ -0,0 +1,2 @@
+source 'http://rubygems.org'
+gem 'redis', :path => "#{Dir.home}/redis-rb"
View
14 Gemfile.lock
@@ -0,0 +1,14 @@
+PATH
+ remote: /home/ardsrk/redis-rb
+ specs:
+ redis (3.0.0.rc1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ redis!
View
2  example.rb
@@ -1,6 +1,6 @@
require 'rubygems'
require 'redis'
-require 'redis-timeseries'
+require "#{Dir.pwd}/lib/redis_time_series"
# To show the lib implementation here we use a timestep of just one second.
# Then we sample every 0.1 seconds, producing on average 10 samples per key.
View
5 redis-timeseries.rb → lib/redis_time_series.rb
@@ -5,6 +5,7 @@ def initialize(prefix,timestep,redis)
@prefix = prefix
@timestep = timestep
@redis = redis
+ @i = 0
end
def normalize_time(t)
@@ -32,10 +33,10 @@ def tsdecode(data)
end
end
- def add(data,origin_time=nil)
+ def add(data, origin_time=nil, clock=Time)
data = tsencode(data)
origin_time = tsencode(origin_time) if origin_time
- now = Time.now.to_f
+ now = clock.now.to_f
value = "#{now}\x01#{data}"
value << "\x01#{origin_time}" if origin_time
value << "\x00"
View
24 spec/redis_time_series_spec.rb
@@ -0,0 +1,24 @@
+require 'ostruct'
+require_relative './spec_helper'
+require_relative '../lib/redis_time_series'
+
+describe RedisTimeSeries do
+ before do
+ @r = Redis.new
+ @prefix = 'test'
+ @timestep = 1
+ @it = RedisTimeSeries.new(@prefix, @timestep, @r)
+ @now = Time.now
+ end
+
+ describe '#add' do
+ it "adds given value to the time key" do
+ now = Time.now
+ clock = OpenStruct.new(:now => now)
+ expected = '1'
+ @it.add(expected, nil, clock)
+ result = @it.fetch_timestep(clock.now).first
+ result[:data].must_equal expected
+ end
+ end
+end
View
7 spec/spec_helper.rb
@@ -0,0 +1,7 @@
+# loads bundler and ensures all gems in Gemfile.lock are installed
+require 'bundler/setup'
+
+# 'minitest/autorun' loads necessary dependencies like minitest/spec.
+require 'minitest/autorun'
+
+require 'redis'

No commit comments for this range

Something went wrong with that request. Please try again.