redis-stream 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -0
- data/lib/redis/stream/client.rb +21 -11
- data/lib/redis/stream/inspect.rb +18 -6
- data/lib/redis/stream/version.rb +1 -1
- data/redis-stream.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2003a3a4fd95c727e14279d50acf299abd6737a41e35d9f158423ba66403800d
|
4
|
+
data.tar.gz: 6677b422a7740963c3076a3bf832ff1a65ce26cb75345123847fc8b598574c32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 518e77d3732aff505a6303fe4e2bed3b26e172a9ecc1b1ddeda4025097414cc310c591aeac800d27d3feec7e2bc2a86e57fa2a454c4b6cfcac76155cd7ccd809
|
7
|
+
data.tar.gz: 0b81242d27148e2fc71787e7cc62a29abf1edaa28c4b81a9f29135c48a8def5edcc2a282fe78b9c945e560203d951b7e9d9ab44315b9507df41655c24147638a
|
data/Gemfile.lock
CHANGED
@@ -2,6 +2,7 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
redis-stream (0.4.6)
|
5
|
+
connection_pool (~> 2.2)
|
5
6
|
moneta (~> 1.2)
|
6
7
|
multi_json (~> 1.14)
|
7
8
|
redis (= 4.1.3)
|
@@ -10,6 +11,7 @@ PATH
|
|
10
11
|
GEM
|
11
12
|
remote: https://rubygems.org/
|
12
13
|
specs:
|
14
|
+
connection_pool (2.2.2)
|
13
15
|
json (2.3.0)
|
14
16
|
minitest (5.13.0)
|
15
17
|
moneta (1.2.1)
|
data/lib/redis/stream/client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#encoding: UTF-8
|
2
2
|
require "redis"
|
3
|
+
require "connection_pool"
|
3
4
|
require "logger"
|
4
5
|
require "json"
|
5
6
|
require "thread"
|
@@ -46,19 +47,19 @@ class Redis
|
|
46
47
|
@group = group_name
|
47
48
|
if options.include?('redis')
|
48
49
|
@logger.info("Taking REDIS as a parameter")
|
49
|
-
@
|
50
|
+
@redis_pool = ConnectionPool.new(size: 10, timeout: 5) { options['redis'] }
|
50
51
|
elsif Redis::Stream::Config.file_exists? && Redis::Stream::Config.include?(:redis)
|
51
52
|
@logger.info("Taking REDIS from config file")
|
52
|
-
@
|
53
|
+
@redis_pool = ConnectionPool.new(size: 10, timeout: 5) { Redis.new(Redis::Stream::Config[:redis]) }
|
53
54
|
else
|
54
55
|
@logger.info("Instantiating REDIS")
|
55
|
-
@
|
56
|
+
@redis_pool = ConnectionPool.new(size: 10, timeout: 5) { Redis.new(host: host, port: port, db: db) }
|
56
57
|
end
|
57
58
|
@consumer_id = "#{@name}-#{@group}-#{Process.pid}"
|
58
59
|
@non_blocking = nil
|
59
60
|
# @send_queue = []
|
60
61
|
|
61
|
-
raise "No redis" if @
|
62
|
+
raise "No redis" if @redis_pool.nil? || @redis_pool.available == 0
|
62
63
|
|
63
64
|
if options.has_key?('tracer') && !options['tracer'].nil?
|
64
65
|
OpenTracing.global_tracer = options["tracer"]
|
@@ -89,7 +90,10 @@ class Redis
|
|
89
90
|
to = options["to"]
|
90
91
|
group = options["group"]
|
91
92
|
payload = build_payload(data, options)
|
92
|
-
add_id =
|
93
|
+
add_id = nil
|
94
|
+
@redis_pool.with do |redis|
|
95
|
+
add_id = redis.xadd(@stream, payload)
|
96
|
+
end
|
93
97
|
|
94
98
|
@logger.info("#{@consumer_id} - send to '#{to}' in group '#{group}' with id '#{add_id}' of type '#{type}'")
|
95
99
|
end
|
@@ -265,7 +269,9 @@ class Redis
|
|
265
269
|
def setup_stream
|
266
270
|
if @group
|
267
271
|
begin
|
268
|
-
@
|
272
|
+
@redis_pool.with do |redis|
|
273
|
+
redis.xgroup(:create, @stream, @group, '$', mkstream: true)
|
274
|
+
end
|
269
275
|
@logger.info("#{@consumer_id} - Group #{@group} created")
|
270
276
|
rescue Redis::CommandError => e
|
271
277
|
@logger.error("#{@consumer_id} - Group #{@group} exists")
|
@@ -306,13 +312,17 @@ class Redis
|
|
306
312
|
# @param [Boolean] passthrough Receive all messages also the ones intended for other consumers
|
307
313
|
def read_next_message_from_stream(async = true, passthrough = false)
|
308
314
|
if @state == Redis::Stream::State::RUNNING
|
309
|
-
result =
|
310
|
-
|
311
|
-
|
315
|
+
result = nil
|
316
|
+
@redis_pool.with do |redis|
|
317
|
+
result = redis.xread(@stream, @lastid, block: 1000, count: 1) if @group.nil?
|
318
|
+
result = redis.xreadgroup(@group, @consumer_id, @stream, '>', block: 1000, count: 1) if @group
|
319
|
+
end
|
312
320
|
unless result.empty?
|
313
321
|
id, data_out = result[@stream][0]
|
314
|
-
ack_count =
|
315
|
-
|
322
|
+
ack_count = 0
|
323
|
+
@redis_pool.with do |redis|
|
324
|
+
ack_count = redis.xack(@stream, @group, id) if @group
|
325
|
+
end
|
316
326
|
tracer_data = JSON.parse(data_out["tracer"])
|
317
327
|
unless tracer_data.nil? || tracer_data.empty?
|
318
328
|
#trace_scope.span.log_kv('has_tracer' => true)
|
data/lib/redis/stream/inspect.rb
CHANGED
@@ -3,34 +3,46 @@ class Redis
|
|
3
3
|
module Stream
|
4
4
|
module Inspect
|
5
5
|
def groups
|
6
|
-
@
|
6
|
+
@redis_pool.with do |redis|
|
7
|
+
redis.xinfo("groups", @stream)
|
8
|
+
end
|
7
9
|
rescue Exception => e
|
8
10
|
@logger.error("#{@consumer_id} - #{e.message}")
|
9
11
|
{}
|
10
12
|
end
|
11
13
|
|
12
14
|
def info
|
13
|
-
@
|
15
|
+
@redis_pool.with do |redis|
|
16
|
+
redis.xinfo("stream", @stream)
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
def consumers(group = @group)
|
17
|
-
@
|
21
|
+
@redis_pool.with do |redis|
|
22
|
+
redis.xinfo("consumers", @stream, group)
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
def del_consumer(group = @group, consumer = @consumer_id)
|
21
27
|
@logger.info("#{@consumer_id} - deleting consumer #{group}-#{consumer}")
|
22
|
-
@
|
28
|
+
@redis_pool.with do |redis|
|
29
|
+
redis.xgroup('DELCONSUMER', @stream, group, consumer)
|
30
|
+
end
|
23
31
|
end
|
24
32
|
|
25
33
|
def del_group(group = @group)
|
26
34
|
if consumers(group).length == 0 && groups.map { |m| m["name"] }.include?(group)
|
27
35
|
@logger.info("#{@consumer_id} - deleting group #{group}")
|
28
|
-
@
|
36
|
+
@redis_pool.with do |redis|
|
37
|
+
redis.xgroup('DESTROY', @stream, group)
|
38
|
+
end
|
29
39
|
end
|
30
40
|
end
|
31
41
|
|
32
42
|
def pending_messages
|
33
|
-
@redis
|
43
|
+
@redis_pool.with do |redis|
|
44
|
+
redis.xrange(@stream)
|
45
|
+
end
|
34
46
|
end
|
35
47
|
end #Inspect
|
36
48
|
end #Stream
|
data/lib/redis/stream/version.rb
CHANGED
data/redis-stream.gemspec
CHANGED
@@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.add_development_dependency "rake", "~> 13.0"
|
41
41
|
spec.add_development_dependency "minitest", "~> 5.0"
|
42
42
|
spec.add_dependency "redis", "4.1.3"
|
43
|
+
spec.add_dependency "connection_pool", "~> 2.2"
|
43
44
|
spec.add_dependency "moneta", "~> 1.2"
|
44
45
|
spec.add_dependency "multi_json", "~> 1.14"
|
45
46
|
spec.add_dependency "zipkin", "~> 1.6.1"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mehmet Celik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 4.1.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: connection_pool
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.2'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: moneta
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|