redis-stream 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e51c4737c9df5802350f4542ff2174d94b1c04d2822e7cfa8a0228add8b5064
4
- data.tar.gz: f6943fea98b8deb03c2308e12c7b361e751c58f178830f7e572cfbfb9c0715ff
3
+ metadata.gz: 39b625a413edc217bd17ecda0c8f6dc899507cdc0535169d464210c2cd3d891b
4
+ data.tar.gz: d3ae887d8623687c190672a30bed816158e3fc043c33d2aa2b1488bcae653541
5
5
  SHA512:
6
- metadata.gz: 79236d75161bb94c395021424287f6d8d980f580d1d24fb841ccae07b5afc5fd43054dc0d8f766db032eaca517075ced1c0dbff824818a34fa49e90c89356d8c
7
- data.tar.gz: a89ed5e218e74e1a0688ec7f587466f3818d92d5f36c09e7df795ae1bf7b36a2f1a36666091d21b2b044ff6acf7d36155167185ac6838490901df367e83d1c31
6
+ metadata.gz: 163921136b188cd050a536bd3b6f7023401a2c41aae19d6bf5061ac5bb926e1d92a46799fb1868de8f3ddbb2f80817d80b9d7976a684e225b4d4eaf7e1d0afad
7
+ data.tar.gz: 5d6cb36afb6089e13775e7119c7bd453c78fe6aeba9e39a423c41b3ad06e312e8b6db5c5744034341bb69fdd440090882c26598f48421838017a1e10a5cfb0e4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redis-stream (0.1.0)
4
+ redis-stream (0.2.0)
5
5
  moneta (~> 1.2)
6
6
  multi_json (~> 1.14)
7
7
  redis (= 4.1.3)
data/README.md CHANGED
@@ -63,7 +63,7 @@ configure do
63
63
 
64
64
  get '/:name' do
65
65
  halt 500, 'name parameter not found' unless params.include?(:name)
66
- result = settings.redis_stream.sync_add(params[:name], "time_out" => 60)
66
+ result = settings.redis_stream.sync_add(params[:name], "group" => "GREETER", "time_out" => 60)
67
67
  @name = params[:name]
68
68
  @reversed_name = result[payload]
69
69
  erb :index
@@ -74,9 +74,23 @@ __END__
74
74
 
75
75
  <p>Hello, <%= @name %>!</p>
76
76
  <p><%= @reversed_name</p>
77
-
78
77
  ```
79
78
 
79
+ # reverse_greeter.rb
80
+ ```ruby
81
+ require 'redis-stream'
82
+
83
+ reverse_greeter = Redis::Stream::Client.new("greetings", "GREETER", "reverse_greeter")
84
+ reverse_greeter.on_message do |message|
85
+ begin
86
+ greeting = message['payload']
87
+ reverse_greeter.add(greeting.reverse, "to" => message['from'])
88
+ rescue Exception => e
89
+ end
90
+ end
91
+
92
+ reverse_greeter.start(true, false)
93
+ ```
80
94
 
81
95
  ## Development
82
96
 
@@ -29,7 +29,7 @@ class Redis
29
29
  port = options["port"]
30
30
  db = options["db"]
31
31
  @logger = options["logger"]
32
- @cache = Redis::Stream::DataCache.new
32
+ @cache = options.include?('caching') && options['caching'] ? Redis::Stream::DataCache.new : nil
33
33
 
34
34
  @name = name
35
35
  @state = Redis::Stream::State::IDLE
@@ -182,29 +182,31 @@ class Redis
182
182
 
183
183
  payload = nil
184
184
 
185
- if options["cache_key"].nil?
186
- cache_key = @cache.build_key(data)
187
- if @cache.include?(cache_key)
188
- if data && data.include?('from_cache') && data['from_cache'].eql?(0)
189
- @cache.delete(cache_key)
190
- @logger.info("#{@consumer_id} - invalidating cache with key #{cache_key}")
191
- else
192
- payload = {
193
- type: type,
194
- from: to,
195
- from_group: group,
196
- to: @consumer_id,
197
- to_group: @group,
198
- payload: @cache[cache_key].to_json
199
- }
200
- @logger.info("#{@consumer_id} - fetching from cache with key #{cache_key}")
201
- end
185
+ unless @cache.nil?
186
+ if options["cache_key"].nil?
187
+ cache_key = @cache.build_key(data)
188
+ if @cache.include?(cache_key)
189
+ if data && data.include?('from_cache') && data['from_cache'].eql?(0)
190
+ @cache.delete(cache_key)
191
+ @logger.info("#{@consumer_id} - invalidating cache with key #{cache_key}")
192
+ else
193
+ payload = {
194
+ type: type,
195
+ from: to,
196
+ from_group: group,
197
+ to: @consumer_id,
198
+ to_group: @group,
199
+ payload: @cache[cache_key].to_json
200
+ }
201
+ @logger.info("#{@consumer_id} - fetching from cache with key #{cache_key}")
202
+ end
202
203
 
204
+ end
205
+ else
206
+ @cache[options["cache_key"]] = data
203
207
  end
204
- else
205
- @cache[options["cache_key"]] = data
206
- end
207
208
 
209
+ end
208
210
  if payload.nil?
209
211
  payload = {
210
212
  type: type,
@@ -1,6 +1,6 @@
1
1
  #encoding: UTF-8
2
2
  class Redis
3
3
  module Stream
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Celik