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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +16 -2
- data/lib/redis/stream/client.rb +23 -21
- data/lib/redis/stream/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39b625a413edc217bd17ecda0c8f6dc899507cdc0535169d464210c2cd3d891b
|
4
|
+
data.tar.gz: d3ae887d8623687c190672a30bed816158e3fc043c33d2aa2b1488bcae653541
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 163921136b188cd050a536bd3b6f7023401a2c41aae19d6bf5061ac5bb926e1d92a46799fb1868de8f3ddbb2f80817d80b9d7976a684e225b4d4eaf7e1d0afad
|
7
|
+
data.tar.gz: 5d6cb36afb6089e13775e7119c7bd453c78fe6aeba9e39a423c41b3ad06e312e8b6db5c5744034341bb69fdd440090882c26598f48421838017a1e10a5cfb0e4
|
data/Gemfile.lock
CHANGED
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
|
|
data/lib/redis/stream/client.rb
CHANGED
@@ -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
|
-
|
186
|
-
cache_key
|
187
|
-
|
188
|
-
if
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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,
|
data/lib/redis/stream/version.rb
CHANGED