tokyo_cache_cow 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Tokyo Cache Cow
2
2
 
3
- Tokyo Cache Cow is MemCache protocol speaking cache server. It offers the ability to delete keys based on a substring.
3
+ Tokyo Cache Cow is MemCache protocol speaking cache server. It offers the ability to delete keys based on a substring as well as aggregate functions based on substrings.
4
4
 
5
5
  == Motivation
6
6
 
@@ -60,6 +60,21 @@ But <i>other_key</i> is still peachy.
60
60
  >> Rails.cache.read('other_key')
61
61
  => "other_value"
62
62
 
63
+ === Aggregate functions
64
+
65
+ You can invoke aggregates by using the prefixes <tt>average-</tt>, <tt>count-</tt>, <tt>sum-</tt>, <tt>min-</tt> and <tt>max-</tt>.
66
+
67
+ >> Rails.cache.write('hello1', '1')
68
+ => true
69
+ >> Rails.cache.write('hello2', '2')
70
+ => true
71
+ >> Rails.cache.write('hello3', '3')
72
+ => true
73
+ >> Rails.cache.read('average-hello')
74
+ => "2.0"
75
+ >> Rails.cache.read('sum-hello')
76
+ => "6.0"
77
+
63
78
 
64
79
  == Usage
65
80
 
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
+ :major: 0
2
3
  :build:
3
4
  :minor: 0
4
- :patch: 5
5
- :major: 0
5
+ :patch: 6
@@ -11,11 +11,35 @@ class TokyoCacheCow
11
11
  end
12
12
 
13
13
  def average_match(match)
14
- average_keys = get_match(match)
15
- values = average_keys.map{|ak| get(ak)}.map{|v| Integer(v[:value]) rescue nil}.compact
14
+ values = numeric_values_match(match)
16
15
  values.inject(0.0) { |sum, el| sum + el } / values.size
17
16
  end
18
17
 
18
+ def sum_match(match)
19
+ values = numeric_values_match(match)
20
+ values.inject(0.0) { |sum, el| sum + el }
21
+ end
22
+
23
+ def count_match(match)
24
+ values = numeric_values_match(match)
25
+ values.size
26
+ end
27
+
28
+ def min_match(match)
29
+ values = numeric_values_match(match)
30
+ values.min
31
+ end
32
+
33
+ def max_match(match)
34
+ values = numeric_values_match(match)
35
+ values.max
36
+ end
37
+
38
+ def numeric_values_match(match)
39
+ numeric_keys = get_match(match)
40
+ numeric_keys.map{|ak| get(ak)}.map{|v| Integer(v[:value]) rescue nil}.compact
41
+ end
42
+
19
43
  end
20
44
  end
21
45
  end
@@ -101,11 +101,11 @@ class TokyoCacheCow
101
101
  keys = args.split(/\s+/)
102
102
  keys.each do |k|
103
103
  next unless validate_key(k)
104
-
105
- puts "in get!"
106
-
107
- if k =~ /^average-/
108
- puts "matched!!"
104
+ if k =~ /^(average|sum|count|min|max)-(.*)/
105
+ average = @cache.send(:"#{$1}_match", $2).to_s
106
+ send_data(GetValueReply % [k, "0", average.size])
107
+ send_data(average)
108
+ send_data(Terminator)
109
109
  else
110
110
  if data = @cache.get(k)
111
111
  if command == 'get'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokyo_cache_cow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hull