io_shuten 0.0.3.dev1 → 0.1.0.dev6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,12 +2,19 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "iobuffer", "~> 1.0.0"
4
4
 
5
+ # REDIS STORE
5
6
  gem "hiredis", "~> 0.4.4"
6
7
  gem "redis", "~> 2.2.2", :require => ["redis/connection/hiredis", "redis"]
8
+ gem "redis-namespace"
7
9
 
10
+ # MONGO STORE
8
11
  gem "bson_ext", "~> 1.5.2"
9
12
  gem "mongo", "~> 1.5.2"
10
13
 
14
+ # ZMQ "STORE"
15
+ gem "ffi"
16
+ gem "ffi-rzmq"
17
+
11
18
  group :development, :test do
12
19
  gem "rake"
13
20
  gem "jeweler"
@@ -22,6 +29,8 @@ group :development, :test do
22
29
  gem "yard-blame"
23
30
 
24
31
  gem "pry"
25
- #gem "pry-doc"
26
- end
27
32
 
33
+ gem "alf"
34
+ gem "fastercsv"
35
+ gem "viiite"
36
+ end
data/Gemfile.lock CHANGED
@@ -1,31 +1,46 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
+ alf (0.10.1)
5
+ highline (~> 1.6.2)
6
+ myrrha (~> 1.2.1)
7
+ quickl (~> 0.4.1)
4
8
  bson (1.5.2)
5
9
  bson_ext (1.5.2)
6
10
  bson (= 1.5.2)
7
11
  coderay (0.9.8)
8
12
  diff-lcs (1.1.3)
13
+ fastercsv (1.5.4)
14
+ ffi (1.0.11)
15
+ ffi-rzmq (0.9.3)
16
+ ffi
9
17
  git (1.2.5)
18
+ gnuplot (2.3.6)
19
+ highline (1.6.11)
10
20
  hiredis (0.4.4)
11
21
  iobuffer (1.0.0)
12
22
  jeweler (1.6.4)
13
23
  bundler (~> 1.0)
14
24
  git (>= 1.2.5)
15
25
  rake
26
+ json (1.6.5)
16
27
  method_source (0.6.7)
17
28
  ruby_parser (>= 2.3.1)
18
29
  mongo (1.5.2)
19
30
  bson (= 1.5.2)
20
31
  multi_json (1.0.4)
32
+ myrrha (1.2.2)
21
33
  pry (0.9.7.4)
22
34
  coderay (~> 0.9.8)
23
35
  method_source (~> 0.6.7)
24
36
  ruby_parser (>= 2.3.1)
25
37
  slop (~> 2.1.0)
38
+ quickl (0.4.2)
26
39
  rake (0.9.2.2)
27
40
  redcarpet (2.0.1)
28
41
  redis (2.2.2)
42
+ redis-namespace (1.1.0)
43
+ redis (< 3.0.0)
29
44
  rspec (2.8.0)
30
45
  rspec-core (~> 2.8.0)
31
46
  rspec-expectations (~> 2.8.0)
@@ -46,6 +61,10 @@ GEM
46
61
  simplecov-rcov (0.2.3)
47
62
  simplecov (>= 0.4.1)
48
63
  slop (2.1.0)
64
+ viiite (0.2.0)
65
+ alf (~> 0.10.1)
66
+ gnuplot (~> 2.3.6)
67
+ json
49
68
  yard (0.7.4)
50
69
  yard-blame (0.0.1)
51
70
  yard
@@ -54,7 +73,11 @@ PLATFORMS
54
73
  ruby
55
74
 
56
75
  DEPENDENCIES
76
+ alf
57
77
  bson_ext (~> 1.5.2)
78
+ fastercsv
79
+ ffi
80
+ ffi-rzmq
58
81
  hiredis (~> 0.4.4)
59
82
  iobuffer (~> 1.0.0)
60
83
  jeweler
@@ -63,9 +86,11 @@ DEPENDENCIES
63
86
  rake
64
87
  redcarpet
65
88
  redis (~> 2.2.2)
89
+ redis-namespace
66
90
  rspec (~> 2.8.0)
67
91
  simplecov
68
92
  simplecov-csv
69
93
  simplecov-rcov
94
+ viiite
70
95
  yard
71
96
  yard-blame
data/README.md CHANGED
@@ -59,6 +59,13 @@ Stores content in a mongodb database.
59
59
  Provides basic methods like `#read`, `#write` and `#close`.
60
60
  A logger only needs write and close methods of an IO object.
61
61
 
62
+ ### IO_shuten::Zmq
63
+
64
+ "Stores" content in a zmq socket.
65
+
66
+ Provides basic methods like `#read`, `#write` and `#close`.
67
+ A logger only needs write and close methods of an IO object.
68
+
62
69
 
63
70
  ## Not for production!
64
71
 
data/Rakefile CHANGED
@@ -93,5 +93,11 @@ end
93
93
 
94
94
 
95
95
 
96
- task :default => [:envinfo,:spec]
96
+ desc "Runs complex viiite benchmark suite"
97
+ task :benchmark do
98
+ sh "./benchmarks.sh"
99
+ end
100
+
97
101
 
102
+
103
+ task :default => [:envinfo,:spec]
@@ -0,0 +1,79 @@
1
+ # encoding: utf-8
2
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
+ require "rubygems"
4
+ require "viiite"
5
+ require "bundler/setup"
6
+ require "io_shuten"
7
+ require "logger"
8
+
9
+ lorem_ipsum = <<LOREM
10
+ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
11
+ tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
12
+ At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
13
+ no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
14
+ consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et
15
+ dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo
16
+ dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
17
+ ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
18
+ diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
19
+ voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
20
+ gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
21
+ LOREM
22
+
23
+ tmp_path = File.expand_path("../../tmp", __FILE__)
24
+ Dir.mkdir(tmp_path) unless File.exists?(tmp_path)
25
+
26
+ ioc = IO_shuten.const_get $CUR_IMPL
27
+ runs = 1..5
28
+ internal_loops = 1_024
29
+
30
+ Viiite.bench do |b|
31
+ b.variation_point :ruby, Viiite.which_ruby
32
+ b.variation_point :type, $CUR_IMPL
33
+
34
+ b.range_over(runs, :run) do |run|
35
+
36
+ ioc.purge_instances!
37
+ b.report :writes do
38
+ internal_loops.times do |i|
39
+ iob = ioc.new("wbuff-#{run}-#{i}")
40
+ iob.write lorem_ipsum
41
+ end
42
+ end
43
+
44
+ ioc.purge_instances!
45
+ b.report :logging do
46
+ internal_loops.times do |i|
47
+ logdev = ioc.new("logdev-#{run}-#{i}")
48
+ logger = Logger.new(logdev)
49
+ logger.info lorem_ipsum
50
+ logger.debug "counter: #{run}-#{i}"
51
+ end
52
+ end
53
+
54
+ ioc.purge_instances!
55
+ b.report :file_writes do
56
+ internal_loops.times do |i|
57
+ iob = ioc.new("#{tmp_path}/wbuff-#{run}-#{i}")
58
+ iob.write lorem_ipsum
59
+ iob.save_to_file
60
+ end
61
+ end
62
+
63
+ ioc.purge_instances!
64
+ b.report :file_reads do
65
+ internal_loops.times do |i|
66
+ iob = ioc.new("#{tmp_path}/wmem-#{run}-#{i}")
67
+ iob.write lorem_ipsum
68
+ iob.save_to_file
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ # File cleaning …
75
+ Dir["#{tmp_path}/**/*"].each do |f|
76
+ File.unlink f
77
+ end
78
+
79
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ $LOAD_PATH.unshift File.expand_path("../../benchmark", __FILE__)
3
+
4
+ $CUR_IMPL = "Buffer"
5
+
6
+ require "viiite-template.rb"
7
+
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ $LOAD_PATH.unshift File.expand_path("../../benchmark", __FILE__)
3
+
4
+ $CUR_IMPL = "Memory"
5
+
6
+ require "viiite-template.rb"
7
+
data/benchmarks.sh ADDED
@@ -0,0 +1,59 @@
1
+ #!/bin/bash
2
+ echo "Loading RVM ..."
3
+ [[ -s $rvm_path/scripts/rvm ]] && source $rvm_path/scripts/rvm >/dev/null 2>&1
4
+
5
+ RUBIES="ruby-1.8.7-p357 ree ruby-1.9.2-p290 ruby-1.9.3-p0"
6
+ GEMSET="io_shuten"
7
+ BENCHMARKS=`ls benchmarks`
8
+ BENCH_OUT="benchmark/out.rash"
9
+ BENCH_REP="benchmark/report"
10
+ BENCH_RUN=10
11
+ CUR_RAKE_VER=`gem list rake | awk '$1~/rake/{print $2}'`
12
+
13
+ [[ -e "$BENCH_OUT" ]] && rm $BENCH_OUT && touch $BENCH_OUT
14
+
15
+ for ruby in $RUBIES; do
16
+
17
+ echo
18
+ echo "Switching to: $ruby@$GEMSET"
19
+ rvm use --create $ruby@$GEMSET >/dev/null 2>&1
20
+
21
+ ruby_rake_ver=`gem list rake | awk '$1~/rake/{print $2}'`
22
+
23
+ if [[ "$ruby_rake_ver" != "$CUR_RAKE_VER" ]]; then
24
+ echo "Installing rake $CUR_RAKE_VER ..."
25
+ gem install rake -v=$CUR_RAKE_VER >/dev/null 2>&1
26
+ else
27
+ echo "rake $CUR_RAKE_VER already installed."
28
+ fi
29
+
30
+ bundler_installed=`gem list bundler | awk '$1~/bundler/ { print $1 }'`
31
+
32
+ if [[ -z "$bundler_installed" ]]; then
33
+ echo "Installing bundler ..."
34
+ gem install bundler --pre >/dev/null 2>&1
35
+ else
36
+ echo "bundler already installed."
37
+ fi
38
+
39
+ echo "Installing gems ..."
40
+ bundle install >/dev/null 2>&1
41
+
42
+ echo "Running benchmarks ..."
43
+ for bench in $BENCHMARKS; do
44
+ viiite run --runs=$BENCH_RUN $bench >> $BENCH_OUT 2>/dev/null
45
+ done
46
+
47
+ done
48
+
49
+ viiite report $BENCH_OUT -h --regroup=bench,ruby,type > ${BENCH_REP}.bench-ruby-type.txt
50
+ viiite report $BENCH_OUT -h --regroup=bench,type,ruby > ${BENCH_REP}.bench-type-ruby.txt
51
+ viiite report $BENCH_OUT -h --regroup=ruby,bench,type > ${BENCH_REP}.ruby-bench-type.txt
52
+ viiite report $BENCH_OUT -h --regroup=ruby,type,bench > ${BENCH_REP}.ruby-type-bench.txt
53
+ viiite report $BENCH_OUT -h --regroup=type,bench,ruby > ${BENCH_REP}.type-bench-ruby.txt
54
+ viiite report $BENCH_OUT -h --regroup=type,ruby,bench > ${BENCH_REP}.type-ruby-bench.txt
55
+
56
+ [[ -e "$BENCH_OUT" ]] && rm $BENCH_OUT
57
+
58
+ echo
59
+ echo "Reports created."
data/io_shuten.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "io_shuten"
8
- s.version = "0.0.3.dev1"
8
+ s.version = "0.1.0.dev6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Christoph Grabo"]
12
- s.date = "2012-01-25"
13
- s.description = "IO::shuten \342\200\223 Use databases as IO handler like you would do with files and streams."
12
+ s.date = "2012-01-30"
13
+ s.description = "IO::shuten \u{2013} Use databases as IO handler like you would do with files and streams."
14
14
  s.email = ["chris@dinarrr.com"]
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -29,7 +29,10 @@ Gem::Specification.new do |s|
29
29
  "LICENSE.de",
30
30
  "README.md",
31
31
  "Rakefile",
32
- "benchmark/compare_mem_w_buf.rb",
32
+ "benchmark/viiite-template.rb",
33
+ "benchmarks.sh",
34
+ "benchmarks/buffer.rb",
35
+ "benchmarks/memory.rb",
33
36
  "doc/IO_3A_3ABuffer.html",
34
37
  "doc/IO_shuten.html",
35
38
  "doc/IO_shuten/Base.html",
@@ -81,13 +84,20 @@ Gem::Specification.new do |s|
81
84
  "lib/io_shuten/mongo.rb",
82
85
  "lib/io_shuten/redis.rb",
83
86
  "lib/io_shuten/stores.rb",
87
+ "lib/io_shuten/stores/base_container.rb",
84
88
  "lib/io_shuten/stores/mongo.rb",
85
89
  "lib/io_shuten/stores/mongo/collection.rb",
86
90
  "lib/io_shuten/stores/mongo/gridfs.rb",
87
91
  "lib/io_shuten/stores/redis.rb",
92
+ "lib/io_shuten/stores/redis/container.rb",
88
93
  "lib/io_shuten/stores/redis/key_value.rb",
94
+ "lib/io_shuten/stores/redis/key_value/collection.rb",
95
+ "lib/io_shuten/stores/redis/key_value/single.rb",
89
96
  "lib/io_shuten/stores/redis/pub_sub.rb",
97
+ "lib/io_shuten/stores/redis/pub_sub/publisher.rb",
98
+ "lib/io_shuten/stores/redis/pub_sub/subscriber.rb",
90
99
  "lib/io_shuten/version.rb",
100
+ "lib/io_shuten/zmq.rb",
91
101
  "spec/examples/logger_spec.rb",
92
102
  "spec/lib/buffer_spec.rb",
93
103
  "spec/lib/memory_spec.rb",
@@ -100,13 +110,14 @@ Gem::Specification.new do |s|
100
110
  "spec/lib/stores/redis/pub_sub_spec.rb",
101
111
  "spec/lib/stores/redis_spec.rb",
102
112
  "spec/lib/stores_spec.rb",
113
+ "spec/lib/zmq_spec.rb",
103
114
  "spec/spec_helper.rb"
104
115
  ]
105
116
  s.homepage = "http://github.com/asaaki/io_shuten"
106
117
  s.licenses = ["MIT"]
107
118
  s.require_paths = ["lib"]
108
- s.rubygems_version = "1.8.10"
109
- s.summary = "IO::shuten \342\200\223 Use databases as IO handler. (NOT YET READY FOR PRODUCTION!)"
119
+ s.rubygems_version = "1.8.15"
120
+ s.summary = "IO::shuten \u{2013} Use databases as IO handler. (NOT YET READY FOR PRODUCTION!)"
110
121
 
111
122
  if s.respond_to? :specification_version then
112
123
  s.specification_version = 3
@@ -115,8 +126,11 @@ Gem::Specification.new do |s|
115
126
  s.add_runtime_dependency(%q<iobuffer>, ["~> 1.0.0"])
116
127
  s.add_runtime_dependency(%q<hiredis>, ["~> 0.4.4"])
117
128
  s.add_runtime_dependency(%q<redis>, ["~> 2.2.2"])
129
+ s.add_runtime_dependency(%q<redis-namespace>, [">= 0"])
118
130
  s.add_runtime_dependency(%q<bson_ext>, ["~> 1.5.2"])
119
131
  s.add_runtime_dependency(%q<mongo>, ["~> 1.5.2"])
132
+ s.add_runtime_dependency(%q<ffi>, [">= 0"])
133
+ s.add_runtime_dependency(%q<ffi-rzmq>, [">= 0"])
120
134
  s.add_development_dependency(%q<rake>, [">= 0"])
121
135
  s.add_development_dependency(%q<jeweler>, [">= 0"])
122
136
  s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
@@ -127,12 +141,18 @@ Gem::Specification.new do |s|
127
141
  s.add_development_dependency(%q<yard>, [">= 0"])
128
142
  s.add_development_dependency(%q<yard-blame>, [">= 0"])
129
143
  s.add_development_dependency(%q<pry>, [">= 0"])
144
+ s.add_development_dependency(%q<alf>, [">= 0"])
145
+ s.add_development_dependency(%q<fastercsv>, [">= 0"])
146
+ s.add_development_dependency(%q<viiite>, [">= 0"])
130
147
  else
131
148
  s.add_dependency(%q<iobuffer>, ["~> 1.0.0"])
132
149
  s.add_dependency(%q<hiredis>, ["~> 0.4.4"])
133
150
  s.add_dependency(%q<redis>, ["~> 2.2.2"])
151
+ s.add_dependency(%q<redis-namespace>, [">= 0"])
134
152
  s.add_dependency(%q<bson_ext>, ["~> 1.5.2"])
135
153
  s.add_dependency(%q<mongo>, ["~> 1.5.2"])
154
+ s.add_dependency(%q<ffi>, [">= 0"])
155
+ s.add_dependency(%q<ffi-rzmq>, [">= 0"])
136
156
  s.add_dependency(%q<rake>, [">= 0"])
137
157
  s.add_dependency(%q<jeweler>, [">= 0"])
138
158
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
@@ -143,13 +163,19 @@ Gem::Specification.new do |s|
143
163
  s.add_dependency(%q<yard>, [">= 0"])
144
164
  s.add_dependency(%q<yard-blame>, [">= 0"])
145
165
  s.add_dependency(%q<pry>, [">= 0"])
166
+ s.add_dependency(%q<alf>, [">= 0"])
167
+ s.add_dependency(%q<fastercsv>, [">= 0"])
168
+ s.add_dependency(%q<viiite>, [">= 0"])
146
169
  end
147
170
  else
148
171
  s.add_dependency(%q<iobuffer>, ["~> 1.0.0"])
149
172
  s.add_dependency(%q<hiredis>, ["~> 0.4.4"])
150
173
  s.add_dependency(%q<redis>, ["~> 2.2.2"])
174
+ s.add_dependency(%q<redis-namespace>, [">= 0"])
151
175
  s.add_dependency(%q<bson_ext>, ["~> 1.5.2"])
152
176
  s.add_dependency(%q<mongo>, ["~> 1.5.2"])
177
+ s.add_dependency(%q<ffi>, [">= 0"])
178
+ s.add_dependency(%q<ffi-rzmq>, [">= 0"])
153
179
  s.add_dependency(%q<rake>, [">= 0"])
154
180
  s.add_dependency(%q<jeweler>, [">= 0"])
155
181
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
@@ -160,6 +186,9 @@ Gem::Specification.new do |s|
160
186
  s.add_dependency(%q<yard>, [">= 0"])
161
187
  s.add_dependency(%q<yard-blame>, [">= 0"])
162
188
  s.add_dependency(%q<pry>, [">= 0"])
189
+ s.add_dependency(%q<alf>, [">= 0"])
190
+ s.add_dependency(%q<fastercsv>, [">= 0"])
191
+ s.add_dependency(%q<viiite>, [">= 0"])
163
192
  end
164
193
  end
165
194
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require "redis"
4
+ require "redis-namespace"
4
5
 
5
6
  module IO_shuten
6
7
  # Implementation of the Redis storage
@@ -9,8 +10,8 @@ module IO_shuten
9
10
  #
10
11
  # KeyValue
11
12
  # has different node types.
12
- # Incremental single message store: each write will create a new key.
13
- # Message collection store: all writes go to a single key.
13
+ # Single: all writes go into a single key
14
+ # Collection: every write will create a new key (namespaced)
14
15
  # Good for events or logs.
15
16
  #
16
17
  # PubSub
@@ -31,17 +32,19 @@ module IO_shuten
31
32
  # @param [Symbol] type for backend :key_value => [:single,:collection], for backend :pub_sub => [:publisher,:subscriber]
32
33
  # @param [Object] Redis an instance for this specific node, otherwise the Redis.redis instance will be used
33
34
  def initialize node_name, backend, type, redis_instance = nil
34
- # based on the backend type it should instantiate the corresponding backend store module
35
- node = :nil
36
- case backend
37
- when :key_value
38
- Stores::Redis::KeyValue #.create(type)
39
- when :pub_sub
40
- Stores::Redis::PubSub #.create(type)
35
+ if [String, Symbol].include?(node_name.class)
36
+ unless Redis.instance_exists? node_name
37
+ @node_name = node_name
38
+ redis_instance ||= @@redis
39
+ @container = Stores::Redis::Container.new(node_name, backend, type, redis_instance)
40
+ @@instances << self unless @@instances.include?(self)
41
41
  else
42
- raise ArgumentError, "Backend type unknown. Use :key_value or :pub_sub"
42
+ raise Errors::NodeExistsError, "Node already in pool, replacement is not allowed."
43
+ end
44
+ else
45
+ raise Errors::NodeNameError, "Name must be kind of String or Symbol and can't be nil."
43
46
  end
44
- @@instances << node
47
+
45
48
  end
46
49
 
47
50
  ### class methods ###
@@ -56,19 +59,16 @@ module IO_shuten
56
59
  # Sets a new global redis client for the pool
57
60
  # @return [Object] new redis client
58
61
  def redis= new_redis
59
- @redis = new_redis
62
+ @@redis = new_redis
60
63
  end
61
- end
62
64
 
63
- ### instance methods ###
64
-
65
- def read
66
- end
67
-
68
- def write
69
- end
65
+ def redis_clear!
66
+ keys = @@redis.keys
67
+ keys.each do |key|
68
+ @@redis.del key
69
+ end
70
+ end
70
71
 
71
- def close
72
72
  end
73
73
 
74
74
  end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module IO_shuten::Stores
4
+ # Namespace for mongodb backends
5
+ module BaseContainer
6
+ def read
7
+ # dummy
8
+ end
9
+
10
+ def write data
11
+ # dummy
12
+ end
13
+
14
+ def close
15
+ # dummy
16
+ # we never close/quit the connection
17
+ # because the instance can be a shared one
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ module IO_shuten::Stores::Redis
5
+ # Redis Backend container
6
+ class Container
7
+ include IO_shuten::Stores::BaseContainer
8
+
9
+ attr_reader :redis
10
+ attr :backend, :backend_type
11
+
12
+ def initialize node_name, backend, type, redis_instance = nil
13
+ @node_name = node_name
14
+ use_backend backend
15
+ use_type type
16
+ use_redis redis_instance
17
+ end
18
+
19
+ def use_backend backend
20
+ backends = {:key_value => KeyValue, :pub_sub => PubSub}
21
+ if backends.keys.include?(backend)
22
+ self.extend backends[backend]
23
+ @backend = backend
24
+ else
25
+ raise ArgumentError, "Backend unknown. Use :key_value or :pub_sub"
26
+ end
27
+ end
28
+
29
+ def backend_spec
30
+ [@backend,@backend_type]
31
+ end
32
+
33
+ def use_redis redis
34
+ @redis = redis unless redis == nil
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ module IO_shuten::Stores::Redis::KeyValue
4
+ # Redis Backend type for storing every data piece into its own key (namespace)
5
+ module Collection
6
+
7
+ def read
8
+ result = read_collection
9
+ result.join
10
+ end
11
+
12
+ def read_collection
13
+ coll = @redis.keys("#{@node_name}:*").sort
14
+ coll.inject([]) do |store, key|
15
+ store << (@redis.get(key))
16
+ store
17
+ end
18
+ end
19
+
20
+ def write data
21
+ counter = @redis.keys("#{@node_name}:*").size + 1
22
+ @redis.set "#{@node_name}:#{counter}", data
23
+ end
24
+
25
+ def clear!
26
+ coll = @redis.keys("#{@node_name}:*")
27
+ coll.each{ |key| @redis.del key }
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ module IO_shuten::Stores::Redis::KeyValue
4
+ # Redis Backend type for storing data into a single key (content => array/hash)
5
+ module Single
6
+
7
+ def read
8
+ result = read_raw
9
+ result.join
10
+ end
11
+
12
+ def read_raw
13
+ @redis.lrange @node_name, 0, -1
14
+ end
15
+
16
+ def write data
17
+ @redis.rpush @node_name, data
18
+ end
19
+
20
+ def clear!
21
+ @redis.del @node_name
22
+ end
23
+
24
+ end
25
+ end
@@ -3,5 +3,19 @@
3
3
  module IO_shuten::Stores::Redis
4
4
  # Redis Backend for key-value based storage
5
5
  module KeyValue
6
+
7
+ def use_type type
8
+ types = {:single => KeyValue::Single, :collection => KeyValue::Collection}
9
+ if types.keys.include?(type)
10
+ self.extend types[type]
11
+ @backend_type = type
12
+ else
13
+ raise ArgumentError, "Type for backend unknown. Use :single or :collection"
14
+ end
15
+ end
16
+
6
17
  end
7
18
  end
19
+
20
+ require "io_shuten/stores/redis/key_value/single"
21
+ require "io_shuten/stores/redis/key_value/collection"
File without changes
File without changes
@@ -3,5 +3,17 @@
3
3
  module IO_shuten::Stores::Redis
4
4
  # Redis Backend for pub-sub (event/message) based storage
5
5
  module PubSub
6
+
7
+ def use_type type
8
+ if [:publisher,:subscriber].include?(type)
9
+ @backend_type = type
10
+ else
11
+ raise ArgumentError, "Type for backend unknown. Use :single or :collection"
12
+ end
13
+ end
14
+
6
15
  end
7
16
  end
17
+
18
+ require "io_shuten/stores/redis/pub_sub/publisher"
19
+ require "io_shuten/stores/redis/pub_sub/subscriber"
@@ -6,6 +6,9 @@ module IO_shuten::Stores
6
6
  end
7
7
  end
8
8
 
9
+ require "redis"
10
+ require "redis-namespace"
11
+
9
12
  require "io_shuten/stores/redis/key_value"
10
13
  require "io_shuten/stores/redis/pub_sub"
11
-
14
+ require "io_shuten/stores/redis/container"
@@ -6,6 +6,6 @@ module IO_shuten
6
6
  end
7
7
  end
8
8
 
9
+ require "io_shuten/stores/base_container"
9
10
  require "io_shuten/stores/mongo"
10
11
  require "io_shuten/stores/redis"
11
-