time_window_drop_collector 0.0.9 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -3
- data/lib/time_window_drop_collector/config.rb +2 -2
- data/lib/time_window_drop_collector/version.rb +1 -1
- data/lib/time_window_drop_collector/wrappers/memcache.rb +1 -1
- data/lib/time_window_drop_collector/wrappers/redis.rb +5 -2
- data/test/config_test.rb +5 -5
- data/test/redis_wrapper_test.rb +27 -6
- data/test/test_helper.rb +1 -2
- data/test/wrapper_test.rb +1 -0
- data/time_window_drop_collector.gemspec +1 -1
- metadata +15 -21
data/README.md
CHANGED
@@ -14,6 +14,13 @@ You can also keep record for **different keys**.
|
|
14
14
|
|
15
15
|
### Config
|
16
16
|
|
17
|
+
twdc =
|
18
|
+
TimeWindowDropCollector.new do
|
19
|
+
client <client>, <client_opts> # underneeth client
|
20
|
+
window <seconds> # in seconds
|
21
|
+
slices <num of slices> # one slice every minute
|
22
|
+
end
|
23
|
+
|
17
24
|
These are the default values
|
18
25
|
|
19
26
|
twdc =
|
@@ -23,14 +30,23 @@ These are the default values
|
|
23
30
|
slices 10 # one slice every minute
|
24
31
|
end
|
25
32
|
|
33
|
+
#### Client
|
34
|
+
Can be:
|
35
|
+
|
36
|
+
* :memcache
|
37
|
+
* :redis
|
38
|
+
* :rails
|
39
|
+
* :mock
|
40
|
+
|
26
41
|
### Use
|
27
42
|
|
28
43
|
twdc.drop( "id1" )
|
29
44
|
twdc.drop( "id1" )
|
30
45
|
twdc.drop( "id2" )
|
31
|
-
twdc.drop(
|
46
|
+
twdc.drop( "id1" )
|
32
47
|
|
33
48
|
twdc.count( "id1" ) # => 3
|
49
|
+
twdc.count( "id2" ) # => 1
|
34
50
|
|
35
51
|
# after 10 minutes
|
36
52
|
twdc.count( "id1" ) # => 0
|
@@ -64,5 +80,3 @@ It uses the `Rails.cache` accesible
|
|
64
80
|
TimeWindowDropCollector.new do
|
65
81
|
client :redis, { :host => "host", :port => "port" }
|
66
82
|
end
|
67
|
-
|
68
|
-
At the moment this wrapper does not support auto-key-clean so the stored keys will be there until anyone delete them.
|
@@ -4,11 +4,14 @@ class TimeWindowDropCollector
|
|
4
4
|
attr_reader :client
|
5
5
|
|
6
6
|
def initialize( opts )
|
7
|
-
@client = ::Redis.new(
|
7
|
+
@client = ::Redis.new( opts )
|
8
8
|
end
|
9
9
|
|
10
10
|
def incr( key, expire_time )
|
11
|
-
|
11
|
+
client.multi do
|
12
|
+
client.incr( key )
|
13
|
+
client.expire( key, expire_time )
|
14
|
+
end
|
12
15
|
end
|
13
16
|
|
14
17
|
def values_for( keys )
|
data/test/config_test.rb
CHANGED
@@ -8,16 +8,16 @@ class ConfigTest < Test::Unit::TestCase
|
|
8
8
|
def test_config
|
9
9
|
proc =
|
10
10
|
Proc.new do
|
11
|
-
client "client", "client_opt1"
|
11
|
+
client "client", "client_opt1"
|
12
12
|
window "window"
|
13
13
|
slices "slices"
|
14
14
|
end
|
15
15
|
|
16
16
|
config = TimeWindowDropCollector::Config.extract( proc )
|
17
17
|
|
18
|
-
assert_equal( "client",
|
19
|
-
assert_equal(
|
20
|
-
assert_equal( "window",
|
21
|
-
assert_equal( "slices",
|
18
|
+
assert_equal( "client", config[:client] )
|
19
|
+
assert_equal( "client_opt1", config[:client_opts] )
|
20
|
+
assert_equal( "window", config[:window] )
|
21
|
+
assert_equal( "slices", config[:slices] )
|
22
22
|
end
|
23
23
|
end
|
data/test/redis_wrapper_test.rb
CHANGED
@@ -1,26 +1,47 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
4
|
-
def
|
3
|
+
class RedisMock
|
4
|
+
def multi(&block)
|
5
|
+
yield
|
5
6
|
end
|
7
|
+
def incr(key);end
|
8
|
+
def expire(key);end
|
9
|
+
def mget(keys);end
|
6
10
|
end
|
7
11
|
|
8
|
-
class
|
12
|
+
class RedisWrapperTest < Test::Unit::TestCase
|
9
13
|
def test_initialize
|
10
|
-
Redis.expects( :new ).with( "arg1", "arg2" ).returns( "client" )
|
14
|
+
Redis.expects( :new ).with( ["arg1", "arg2"] ).returns( "client" )
|
11
15
|
wrapper = TimeWindowDropCollector::Wrappers::Redis.new( ["arg1", "arg2"] )
|
16
|
+
|
12
17
|
assert_equal( "client", wrapper.client )
|
13
18
|
end
|
14
19
|
|
15
20
|
def test_incr
|
16
|
-
|
21
|
+
Redis.expects( :new ).returns( RedisMock.new )
|
22
|
+
wrapper = TimeWindowDropCollector::Wrappers::Redis.new( nil )
|
23
|
+
|
17
24
|
wrapper.client.expects( :incr ).with( "key" )
|
25
|
+
wrapper.client.expects( :expire ).with( "key", "expire_time" )
|
26
|
+
|
18
27
|
wrapper.incr( "key", "expire_time" )
|
19
28
|
end
|
20
29
|
|
30
|
+
def test_incr_agregates_commands_under_multi
|
31
|
+
Redis.expects( :new ).returns( RedisMock.new )
|
32
|
+
wrapper = TimeWindowDropCollector::Wrappers::Redis.new( nil )
|
33
|
+
|
34
|
+
wrapper.client.expects( :multi )
|
35
|
+
|
36
|
+
wrapper.incr( nil, nil )
|
37
|
+
end
|
38
|
+
|
21
39
|
def test_values_for
|
22
|
-
|
40
|
+
Redis.expects( :new ).returns( RedisMock.new )
|
41
|
+
wrapper = TimeWindowDropCollector::Wrappers::Redis.new( nil )
|
42
|
+
|
23
43
|
wrapper.client.expects( :mget ).with( "key1", "key2" ).returns( [1, 2] )
|
44
|
+
|
24
45
|
assert_equal( [1, 2], wrapper.values_for( ["key1", "key2"] ))
|
25
46
|
end
|
26
47
|
end
|
data/test/test_helper.rb
CHANGED
data/test/wrapper_test.rb
CHANGED
@@ -12,6 +12,7 @@ class WrapperTest < Test::Unit::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_instance_when_redis
|
15
|
+
Redis.stubs( :new )
|
15
16
|
instance = TimeWindowDropCollector::Wrapper.instance( :redis, ["server", "port"] )
|
16
17
|
assert( instance.is_a? TimeWindowDropCollector::Wrappers::Redis )
|
17
18
|
end
|
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = TimeWindowDropCollector::VERSION
|
8
8
|
s.authors = ["Fernando Guillen", "Carlos Moutinho"]
|
9
9
|
s.email = ["fguillen.mail@gmail.com", "carlosmoutinho@gmail.com"]
|
10
|
-
s.homepage = ""
|
10
|
+
s.homepage = "https://github.com/fguillen/TimeWindowDropCollector"
|
11
11
|
s.summary = "Counter storage system for a concrete time window"
|
12
12
|
s.description = "Counter storage system for a concrete time window"
|
13
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_window_drop_collector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-01-
|
13
|
+
date: 2012-01-25 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
17
|
-
requirement: &
|
17
|
+
requirement: &70114503076580 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - =
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 1.0.21
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70114503076580
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rake
|
28
|
-
requirement: &
|
28
|
+
requirement: &70114503076080 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - =
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.9.2.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70114503076080
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: mocha
|
39
|
-
requirement: &
|
39
|
+
requirement: &70114503075620 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - =
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 0.10.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70114503075620
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: delorean
|
50
|
-
requirement: &
|
50
|
+
requirement: &70114503075160 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - =
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 1.2.0
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70114503075160
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: memcache_mock
|
61
|
-
requirement: &
|
61
|
+
requirement: &70114503074700 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - =
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: 0.0.1
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70114503074700
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: dalli
|
72
|
-
requirement: &
|
72
|
+
requirement: &70114503074320 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70114503074320
|
81
81
|
description: Counter storage system for a concrete time window
|
82
82
|
email:
|
83
83
|
- fguillen.mail@gmail.com
|
@@ -113,7 +113,7 @@ files:
|
|
113
113
|
- test/time_window_drop_collector_test.rb
|
114
114
|
- test/wrapper_test.rb
|
115
115
|
- time_window_drop_collector.gemspec
|
116
|
-
homepage:
|
116
|
+
homepage: https://github.com/fguillen/TimeWindowDropCollector
|
117
117
|
licenses: []
|
118
118
|
post_install_message:
|
119
119
|
rdoc_options: []
|
@@ -125,18 +125,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
125
|
- - ! '>='
|
126
126
|
- !ruby/object:Gem::Version
|
127
127
|
version: '0'
|
128
|
-
segments:
|
129
|
-
- 0
|
130
|
-
hash: 2014524579348861300
|
131
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
129
|
none: false
|
133
130
|
requirements:
|
134
131
|
- - ! '>='
|
135
132
|
- !ruby/object:Gem::Version
|
136
133
|
version: '0'
|
137
|
-
segments:
|
138
|
-
- 0
|
139
|
-
hash: 2014524579348861300
|
140
134
|
requirements: []
|
141
135
|
rubyforge_project: time_window_drop_collector
|
142
136
|
rubygems_version: 1.8.15
|