redistat 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -5
- data/lib/redistat.rb +24 -46
- data/lib/redistat/collection.rb +4 -0
- data/lib/redistat/connection.rb +67 -0
- data/lib/redistat/database.rb +2 -2
- data/lib/redistat/event.rb +16 -3
- data/lib/redistat/finder.rb +4 -0
- data/lib/redistat/label.rb +5 -0
- data/lib/redistat/model.rb +11 -0
- data/lib/redistat/summary.rb +4 -4
- data/lib/redistat/version.rb +2 -2
- data/redistat.gemspec +3 -0
- data/spec/collection_spec.rb +8 -1
- data/spec/connection_spec.rb +61 -0
- data/spec/database_spec.rb +10 -0
- data/spec/model_helper.rb +8 -1
- data/spec/model_spec.rb +60 -26
- data/spec/spec_helper.rb +2 -2
- metadata +41 -6
- data/spec/_redistat_spec.rb +0 -34
data/Gemfile
CHANGED
data/lib/redistat.rb
CHANGED
@@ -10,6 +10,7 @@ require 'json'
|
|
10
10
|
require 'digest/sha1'
|
11
11
|
|
12
12
|
require 'redistat/collection'
|
13
|
+
require 'redistat/connection'
|
13
14
|
require 'redistat/database'
|
14
15
|
require 'redistat/date'
|
15
16
|
require 'redistat/event'
|
@@ -34,51 +35,28 @@ module Redistat
|
|
34
35
|
KEY_EVENT_IDS = ".event_ids"
|
35
36
|
|
36
37
|
class InvalidOptions < ArgumentError; end
|
37
|
-
|
38
|
-
# Provides access to the Redis database. This is shared accross all models and instances.
|
39
|
-
def redis
|
40
|
-
threaded[:redis] ||= connection(*options)
|
41
|
-
end
|
42
|
-
|
43
|
-
def redis=(connection)
|
44
|
-
threaded[:redis] = connection
|
45
|
-
end
|
46
|
-
|
47
|
-
def threaded
|
48
|
-
Thread.current[:redistat] ||= {}
|
49
|
-
end
|
50
|
-
|
51
|
-
# Connect to a redis database.
|
52
|
-
#
|
53
|
-
# @param options [Hash] options to create a message with.
|
54
|
-
# @option options [#to_s] :host ('127.0.0.1') Host of the redis database.
|
55
|
-
# @option options [#to_s] :port (6379) Port number.
|
56
|
-
# @option options [#to_s] :db (0) Database number.
|
57
|
-
# @option options [#to_s] :timeout (0) Database timeout in seconds.
|
58
|
-
# @example Connect to a database in port 6380.
|
59
|
-
# Redistat.connect(:port => 6380)
|
60
|
-
def connect(*options)
|
61
|
-
self.redis = nil
|
62
|
-
@options = options
|
63
|
-
end
|
64
|
-
|
65
|
-
# Return a connection to Redis.
|
66
|
-
#
|
67
|
-
# This is a wapper around Redis.new(options)
|
68
|
-
def connection(*options)
|
69
|
-
Redis.new(*options)
|
70
|
-
end
|
71
|
-
|
72
|
-
def options
|
73
|
-
@options = [] unless defined? @options
|
74
|
-
@options
|
75
|
-
end
|
76
|
-
|
77
|
-
# Clear the database.
|
78
|
-
def flush
|
79
|
-
redis.flushdb
|
80
|
-
end
|
38
|
+
class RedisServerIsTooOld < Exception; end
|
81
39
|
|
82
|
-
|
83
|
-
|
40
|
+
class << self
|
41
|
+
|
42
|
+
def connection(ref = nil)
|
43
|
+
Connection.get(ref)
|
44
|
+
end
|
45
|
+
alias :redis :connection
|
46
|
+
|
47
|
+
def connection=(connection)
|
48
|
+
Connection.add(connection)
|
49
|
+
end
|
50
|
+
alias :redis= :connection=
|
51
|
+
|
52
|
+
def connect(options)
|
53
|
+
Connection.create(options)
|
54
|
+
end
|
55
|
+
|
56
|
+
def flush
|
57
|
+
puts "WARNING: Redistat.flush is deprecated. Use Redistat.redis.flush instead."
|
58
|
+
connection.flushdb
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
84
62
|
end
|
data/lib/redistat/collection.rb
CHANGED
@@ -0,0 +1,67 @@
|
|
1
|
+
module Redistat
|
2
|
+
module Connection
|
3
|
+
|
4
|
+
REQUIRED_SERVER_VERSION = "1.3.10"
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def get(ref = nil)
|
9
|
+
ref ||= :default
|
10
|
+
connections[references[ref]] || create
|
11
|
+
end
|
12
|
+
|
13
|
+
def add(conn, ref = nil)
|
14
|
+
ref ||= :default
|
15
|
+
check_redis_version(conn)
|
16
|
+
references[ref] = conn.client.id
|
17
|
+
connections[conn.client.id] = conn
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(options = {})
|
21
|
+
ref = options.delete(:ref) || :default
|
22
|
+
options.reverse_merge!(default_options)
|
23
|
+
conn = (connections[connection_id(options)] ||= connection(options))
|
24
|
+
references[ref] = conn.client.id
|
25
|
+
conn
|
26
|
+
end
|
27
|
+
|
28
|
+
def connections
|
29
|
+
threaded[:connections] ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def references
|
33
|
+
threaded[:references] ||= {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def threaded
|
37
|
+
Thread.current[:redistat] ||= {}
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def check_redis_version(conn)
|
43
|
+
raise RedisServerIsTooOld if conn.info["redis_version"] < REQUIRED_SERVER_VERSION
|
44
|
+
conn
|
45
|
+
end
|
46
|
+
|
47
|
+
def connection(options)
|
48
|
+
check_redis_version(Redis.new(options))
|
49
|
+
end
|
50
|
+
|
51
|
+
def connection_id(options = {})
|
52
|
+
options.reverse_merge!(default_options)
|
53
|
+
"redis://#{options[:host]}:#{options[:port]}/#{options[:db]}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def default_options
|
57
|
+
{
|
58
|
+
:host => '127.0.0.1',
|
59
|
+
:port => 6379,
|
60
|
+
:db => 0,
|
61
|
+
:timeout => 5
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/redistat/database.rb
CHANGED
data/lib/redistat/event.rb
CHANGED
@@ -4,21 +4,34 @@ module Redistat
|
|
4
4
|
|
5
5
|
attr_reader :id
|
6
6
|
attr_reader :key
|
7
|
+
attr_reader :connection_ref
|
7
8
|
|
8
9
|
attr_accessor :stats
|
9
10
|
attr_accessor :meta
|
10
11
|
attr_accessor :options
|
11
12
|
|
12
13
|
def initialize(scope, label = nil, date = nil, stats = {}, options = {}, meta = {}, is_new = true)
|
13
|
-
@options =
|
14
|
+
@options = parse_options(options)
|
15
|
+
@connection_ref = @options[:connection_ref]
|
14
16
|
@key = Key.new(scope, label, date, @options)
|
15
17
|
@stats = stats ||= {}
|
16
18
|
@meta = meta ||= {}
|
17
19
|
@new = is_new
|
18
20
|
end
|
21
|
+
|
22
|
+
def db
|
23
|
+
super(@connection_ref)
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_options(options)
|
27
|
+
default_options.each do |opt, val|
|
28
|
+
options[opt] = val if options[opt].nil?
|
29
|
+
end
|
30
|
+
options
|
31
|
+
end
|
19
32
|
|
20
33
|
def default_options
|
21
|
-
{ :depth => :hour, :store_event => false }
|
34
|
+
{ :depth => :hour, :store_event => false, :connection_ref => nil }
|
22
35
|
end
|
23
36
|
|
24
37
|
def new?
|
@@ -59,7 +72,7 @@ module Redistat
|
|
59
72
|
|
60
73
|
def save
|
61
74
|
return false if !self.new?
|
62
|
-
Summary.update_all(@key, @stats, depth_limit)
|
75
|
+
Summary.update_all(@key, @stats, depth_limit, @connection_ref)
|
63
76
|
if @options[:store_event]
|
64
77
|
@id = self.next_id
|
65
78
|
db.hmset("#{self.scope}#{KEY_EVENT}#{@id}",
|
data/lib/redistat/finder.rb
CHANGED
data/lib/redistat/label.rb
CHANGED
@@ -3,11 +3,16 @@ module Redistat
|
|
3
3
|
include Database
|
4
4
|
|
5
5
|
attr_reader :raw
|
6
|
+
attr_reader :connection_ref
|
6
7
|
|
7
8
|
def initialize(str, options = {})
|
8
9
|
@options = options
|
9
10
|
@raw = str.to_s
|
10
11
|
end
|
12
|
+
|
13
|
+
def db
|
14
|
+
super(@options[:connection_ref])
|
15
|
+
end
|
11
16
|
|
12
17
|
def name
|
13
18
|
@options[:hashed_label] ? hash : @raw
|
data/lib/redistat/model.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Redistat
|
2
2
|
module Model
|
3
|
+
include Redistat::Database
|
3
4
|
|
4
5
|
def self.included(base)
|
5
6
|
base.extend(self)
|
@@ -10,6 +11,16 @@ module Redistat
|
|
10
11
|
end
|
11
12
|
alias :event :store
|
12
13
|
|
14
|
+
def connect_to(opts = {})
|
15
|
+
Connection.create(opts.merge(:ref => name))
|
16
|
+
options[:connection_ref] = name
|
17
|
+
end
|
18
|
+
|
19
|
+
def connection
|
20
|
+
db(options[:connection_ref])
|
21
|
+
end
|
22
|
+
alias :redis :connection
|
23
|
+
|
13
24
|
def fetch(label, from, till, opts = {})
|
14
25
|
Finder.find({
|
15
26
|
:scope => name,
|
data/lib/redistat/summary.rb
CHANGED
@@ -2,21 +2,21 @@ module Redistat
|
|
2
2
|
class Summary
|
3
3
|
include Database
|
4
4
|
|
5
|
-
def self.update_all(key, stats = {}, depth_limit = nil)
|
5
|
+
def self.update_all(key, stats = {}, depth_limit = nil, connection_ref = nil)
|
6
6
|
stats ||= {}
|
7
7
|
depth_limit ||= key.depth
|
8
8
|
return nil if stats.size == 0
|
9
9
|
Date::DEPTHS.each do |depth|
|
10
|
-
update(key, stats, depth)
|
10
|
+
update(key, stats, depth, connection_ref)
|
11
11
|
break if depth == depth_limit
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def self.update(key, stats, depth)
|
17
|
+
def self.update(key, stats, depth, connection_ref = nil)
|
18
18
|
stats.each do |field, value|
|
19
|
-
db.hincrby key.to_s(depth), field, value
|
19
|
+
db(connection_ref).hincrby key.to_s(depth), field, value
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
data/lib/redistat/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Redistat
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
2
|
+
VERSION = "0.0.5"
|
3
|
+
end
|
data/redistat.gemspec
CHANGED
@@ -24,4 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_runtime_dependency 'redis', '>= 2.1.1'
|
25
25
|
s.add_runtime_dependency 'system_timer', '>= 1.0.0'
|
26
26
|
s.add_runtime_dependency 'time_ext', '>= 0.2.8'
|
27
|
+
|
28
|
+
s.add_development_dependency 'rspec', '>= 2.1.0'
|
29
|
+
s.add_development_dependency 'yard', '>= 0.6.3'
|
27
30
|
end
|
data/spec/collection_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Redistat::Collection do
|
4
4
|
|
5
|
-
it "should
|
5
|
+
it "should initialize properly" do
|
6
6
|
options = {:from => "from", :till => "till", :depth => "depth"}
|
7
7
|
result = Redistat::Collection.new(options)
|
8
8
|
result.from.should == options[:from]
|
@@ -10,4 +10,11 @@ describe Redistat::Collection do
|
|
10
10
|
result.depth.should == options[:depth]
|
11
11
|
end
|
12
12
|
|
13
|
+
it "should have a total property" do
|
14
|
+
col = Redistat::Collection.new()
|
15
|
+
col.total.should == {}
|
16
|
+
col.total = {:foo => "bar"}
|
17
|
+
col.total.should == {:foo => "bar"}
|
18
|
+
end
|
19
|
+
|
13
20
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
include Redistat
|
3
|
+
|
4
|
+
describe Redistat::Connection do
|
5
|
+
|
6
|
+
it "should have a valid Redis client instance" do
|
7
|
+
Redistat.redis.should_not be_nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have initialized custom testing connection" do
|
11
|
+
redis = Redistat.redis
|
12
|
+
redis.client.host.should == '127.0.0.1'
|
13
|
+
redis.client.port.should == 8379
|
14
|
+
redis.client.db.should == 15
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be able to set and get data" do
|
18
|
+
redis = Redistat.redis
|
19
|
+
redis.set("hello", "world")
|
20
|
+
redis.get("hello").should == "world"
|
21
|
+
redis.del("hello").should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be able to store hashes to Redis" do
|
25
|
+
redis = Redistat.redis
|
26
|
+
redis.hset("hash", "field", "1")
|
27
|
+
redis.hget("hash", "field").should == "1"
|
28
|
+
redis.hincrby("hash", "field", 1)
|
29
|
+
redis.hget("hash", "field").should == "2"
|
30
|
+
redis.hincrby("hash", "field", -1)
|
31
|
+
redis.hget("hash", "field").should == "1"
|
32
|
+
redis.del("hash")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be accessible from Redistat module" do
|
36
|
+
Redistat.redis.should == Connection.get
|
37
|
+
Redistat.redis.should == Redistat.connection
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should handle multiple connections with refs" do
|
41
|
+
Redistat.redis.client.db.should == 15
|
42
|
+
Redistat.connect(:port => 8379, :db => 14, :ref => "Custom")
|
43
|
+
Redistat.redis.client.db.should == 15
|
44
|
+
Redistat.redis("Custom").client.db.should == 14
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should be able to overwrite default and custom refs" do
|
48
|
+
Redistat.redis.client.db.should == 15
|
49
|
+
Redistat.connect(:port => 8379, :db => 14)
|
50
|
+
Redistat.redis.client.db.should == 14
|
51
|
+
|
52
|
+
Redistat.redis("Custom").client.db.should == 14
|
53
|
+
Redistat.connect(:port => 8379, :db => 15, :ref => "Custom")
|
54
|
+
Redistat.redis("Custom").client.db.should == 15
|
55
|
+
|
56
|
+
# Reset the default connection to the testing server or all hell
|
57
|
+
# might brake loose from the rest of the specs
|
58
|
+
Redistat.connect(:port => 8379, :db => 15)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/spec/model_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "redistat"
|
2
2
|
|
3
|
-
class
|
3
|
+
class ModelHelper1
|
4
4
|
include Redistat::Model
|
5
5
|
|
6
6
|
|
@@ -13,4 +13,11 @@ class ModelHelper2
|
|
13
13
|
store_event true
|
14
14
|
hashed_label true
|
15
15
|
|
16
|
+
end
|
17
|
+
|
18
|
+
class ModelHelper3
|
19
|
+
include Redistat::Model
|
20
|
+
|
21
|
+
connect_to :port => 8379, :db => 14
|
22
|
+
|
16
23
|
end
|
data/spec/model_spec.rb
CHANGED
@@ -5,11 +5,13 @@ describe Redistat::Model do
|
|
5
5
|
include Redistat::Database
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
|
8
|
+
ModelHelper1.redis.flushdb
|
9
|
+
ModelHelper2.redis.flushdb
|
10
|
+
ModelHelper3.redis.flushdb
|
9
11
|
end
|
10
12
|
|
11
13
|
it "should should name itself correctly" do
|
12
|
-
|
14
|
+
ModelHelper1.send(:name).should == "ModelHelper1"
|
13
15
|
ModelHelper2.send(:name).should == "ModelHelper2"
|
14
16
|
end
|
15
17
|
|
@@ -18,49 +20,81 @@ describe Redistat::Model do
|
|
18
20
|
ModelHelper2.store_event.should == true
|
19
21
|
ModelHelper2.hashed_label.should == true
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
23
|
+
ModelHelper1.depth.should == nil
|
24
|
+
ModelHelper1.store_event.should == nil
|
25
|
+
ModelHelper1.hashed_label.should == nil
|
26
|
+
ModelHelper1.depth(:hour)
|
27
|
+
ModelHelper1.depth.should == :hour
|
28
|
+
ModelHelper1.store_event(true)
|
29
|
+
ModelHelper1.store_event.should == true
|
30
|
+
ModelHelper1.hashed_label(true)
|
31
|
+
ModelHelper1.hashed_label.should == true
|
32
|
+
ModelHelper1.options[:depth] = nil
|
33
|
+
ModelHelper1.options[:store_event] = nil
|
34
|
+
ModelHelper1.options[:hashed_label] = nil
|
35
|
+
ModelHelper1.depth.should == nil
|
36
|
+
ModelHelper1.store_event.should == nil
|
37
|
+
ModelHelper1.hashed_label.should == nil
|
36
38
|
end
|
37
39
|
|
38
40
|
it "should store and fetch stats" do
|
39
|
-
|
40
|
-
|
41
|
+
ModelHelper1.store("sheep.black", {:count => 6, :weight => 461}, 4.hours.ago)
|
42
|
+
ModelHelper1.store("sheep.black", {:count => 2, :weight => 156})
|
41
43
|
|
42
|
-
stats =
|
44
|
+
stats = ModelHelper1.fetch("sheep.black", 2.hours.ago, 1.hour.from_now)
|
43
45
|
stats.total["count"].should == 2
|
44
46
|
stats.total["weight"].should == 156
|
45
47
|
stats.first.should == stats.total
|
46
48
|
|
47
|
-
stats =
|
49
|
+
stats = ModelHelper1.fetch("sheep.black", 5.hours.ago, 1.hour.from_now)
|
48
50
|
stats.total[:count].should == 8
|
49
51
|
stats.total[:weight].should == 617
|
50
52
|
stats.first.should == stats.total
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
+
ModelHelper1.store("sheep.white", {:count => 5, :weight => 393}, 4.hours.ago)
|
55
|
+
ModelHelper1.store("sheep.white", {:count => 4, :weight => 316})
|
54
56
|
|
55
|
-
stats =
|
57
|
+
stats = ModelHelper1.fetch("sheep.white", 2.hours.ago, 1.hour.from_now)
|
56
58
|
stats.total[:count].should == 4
|
57
59
|
stats.total[:weight].should == 316
|
58
60
|
stats.first.should == stats.total
|
59
61
|
|
60
|
-
stats =
|
62
|
+
stats = ModelHelper1.fetch("sheep.white", 5.hours.ago, 1.hour.from_now)
|
61
63
|
stats.total[:count].should == 9
|
62
64
|
stats.total[:weight].should == 709
|
63
65
|
stats.first.should == stats.total
|
64
66
|
end
|
65
67
|
|
66
|
-
|
68
|
+
it "should connect to different Redis servers on a per-model basis" do
|
69
|
+
ModelHelper3.redis.client.db.should == 14
|
70
|
+
|
71
|
+
ModelHelper3.store("sheep.black", {:count => 6, :weight => 461}, 4.hours.ago)
|
72
|
+
ModelHelper3.store("sheep.black", {:count => 2, :weight => 156})
|
73
|
+
|
74
|
+
db.keys("*").should be_empty
|
75
|
+
ModelHelper1.redis.keys("*").should be_empty
|
76
|
+
db("ModelHelper3").keys("*").should have(5).items
|
77
|
+
ModelHelper3.redis.keys("*").should have(5).items
|
78
|
+
|
79
|
+
stats = ModelHelper3.fetch("sheep.black", 2.hours.ago, 1.hour.from_now)
|
80
|
+
stats.total["count"].should == 2
|
81
|
+
stats.total["weight"].should == 156
|
82
|
+
stats = ModelHelper3.fetch("sheep.black", 5.hours.ago, 1.hour.from_now)
|
83
|
+
stats.total[:count].should == 8
|
84
|
+
stats.total[:weight].should == 617
|
85
|
+
|
86
|
+
ModelHelper3.connect_to(:port => 8379, :db => 13)
|
87
|
+
ModelHelper3.redis.client.db.should == 13
|
88
|
+
|
89
|
+
stats = ModelHelper3.fetch("sheep.black", 5.hours.ago, 1.hour.from_now)
|
90
|
+
stats.total.should == {}
|
91
|
+
|
92
|
+
ModelHelper3.connect_to(:port => 8379, :db => 14)
|
93
|
+
ModelHelper3.redis.client.db.should == 14
|
94
|
+
|
95
|
+
stats = ModelHelper3.fetch("sheep.black", 5.hours.ago, 1.hour.from_now)
|
96
|
+
stats.total[:count].should == 8
|
97
|
+
stats.total[:weight].should == 617
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redistat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jim Myhrberg
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-28 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -98,6 +98,38 @@ dependencies:
|
|
98
98
|
version: 0.2.8
|
99
99
|
type: :runtime
|
100
100
|
version_requirements: *id005
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: rspec
|
103
|
+
prerelease: false
|
104
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 11
|
110
|
+
segments:
|
111
|
+
- 2
|
112
|
+
- 1
|
113
|
+
- 0
|
114
|
+
version: 2.1.0
|
115
|
+
type: :development
|
116
|
+
version_requirements: *id006
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: yard
|
119
|
+
prerelease: false
|
120
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: 1
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
- 6
|
129
|
+
- 3
|
130
|
+
version: 0.6.3
|
131
|
+
type: :development
|
132
|
+
version_requirements: *id007
|
101
133
|
description: A Redis-backed statistics storage and querying library written in Ruby.
|
102
134
|
email:
|
103
135
|
- contact@jimeh.me
|
@@ -118,6 +150,7 @@ files:
|
|
118
150
|
- Rakefile
|
119
151
|
- lib/redistat.rb
|
120
152
|
- lib/redistat/collection.rb
|
153
|
+
- lib/redistat/connection.rb
|
121
154
|
- lib/redistat/core_ext/date.rb
|
122
155
|
- lib/redistat/core_ext/fixnum.rb
|
123
156
|
- lib/redistat/core_ext/time.rb
|
@@ -134,8 +167,9 @@ files:
|
|
134
167
|
- lib/redistat/summary.rb
|
135
168
|
- lib/redistat/version.rb
|
136
169
|
- redistat.gemspec
|
137
|
-
- spec/_redistat_spec.rb
|
138
170
|
- spec/collection_spec.rb
|
171
|
+
- spec/connection_spec.rb
|
172
|
+
- spec/database_spec.rb
|
139
173
|
- spec/date_spec.rb
|
140
174
|
- spec/db/.emptydir
|
141
175
|
- spec/event_spec.rb
|
@@ -185,8 +219,9 @@ signing_key:
|
|
185
219
|
specification_version: 3
|
186
220
|
summary: A Redis-backed statistics storage and querying library written in Ruby.
|
187
221
|
test_files:
|
188
|
-
- spec/_redistat_spec.rb
|
189
222
|
- spec/collection_spec.rb
|
223
|
+
- spec/connection_spec.rb
|
224
|
+
- spec/database_spec.rb
|
190
225
|
- spec/date_spec.rb
|
191
226
|
- spec/db/.emptydir
|
192
227
|
- spec/event_spec.rb
|
data/spec/_redistat_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Redistat do
|
4
|
-
include Redistat::Database
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
db.flushdb
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should have a valid Redis client instance" do
|
11
|
-
db.should_not be_nil
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should be connected to the testing server" do
|
15
|
-
db.client.port.should == 8379
|
16
|
-
db.client.host.should == "127.0.0.1"
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should be able to set and get data" do
|
20
|
-
db.set("hello", "world")
|
21
|
-
db.get("hello").should == "world"
|
22
|
-
db.del("hello").should be_true
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should be able to store hashes to Redis" do
|
26
|
-
db.hset("key", "field", "1")
|
27
|
-
db.hget("key", "field").should == "1"
|
28
|
-
db.hincrby("key", "field", 1)
|
29
|
-
db.hget("key", "field").should == "2"
|
30
|
-
db.hincrby("key", "field", -1)
|
31
|
-
db.hget("key", "field").should == "1"
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|