redis-stream 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/Gemfile.lock +1 -1
- data/README.md +46 -18
- data/config.yml +3 -1
- data/lib/redis/stream/client.rb +8 -1
- data/lib/redis/stream/config.rb +24 -4
- data/lib/redis/stream/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e636f1c98003bb96c0ca288b66e7ec9e8a32232a2eb1a06c3c5291df97bed4b
|
4
|
+
data.tar.gz: d9e9533cc0175ceb705d4f9d9964f5fb5f94c517df3bd3cd5614c12dc2962c76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b900b2614e55c5a470cf1b54f0751475c4186a9a1272bd1d0acefb0a9827139ed34d4e857494396333a2ff4c0f4556050df7400316f236502a4261f2916aab05
|
7
|
+
data.tar.gz: cf969f706a177b0636f0100909987fc52fee799b502accae266a697524068d77ce9d12919b9bc80dda6acaa055d6ef9532a85b183fcfa0c0333ff55f0d89a507
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Redis::Stream
|
2
|
-
### !!!Use jRuby for now. It has a weird bug in cruby
|
3
2
|
|
4
3
|
Sugar coating Redis Streams
|
5
4
|
|
5
|
+
TODO: add documentation
|
6
|
+
|
6
7
|
## Installation
|
7
8
|
|
8
9
|
Add this line to your application's Gemfile:
|
@@ -21,9 +22,22 @@ Or install it yourself as:
|
|
21
22
|
|
22
23
|
## Usage
|
23
24
|
|
25
|
+
Load the stream library
|
26
|
+
```ruby
|
27
|
+
require 'redis/stream'
|
28
|
+
```
|
29
|
+
Available objects
|
30
|
+
### Redis::Stream::Client
|
31
|
+
### Redis::Stream::Config
|
32
|
+
### Redis::Stream::Inspect
|
33
|
+
### Redis::Stream::Type
|
34
|
+
### Redis::Stream::DataCache
|
35
|
+
|
36
|
+
|
37
|
+
|
24
38
|
#### A simple non-blocking example
|
25
39
|
```ruby
|
26
|
-
require 'redis
|
40
|
+
require 'redis/stream'
|
27
41
|
s1 = Redis::Stream::Client.new("test", "LIST", 't1')
|
28
42
|
s2 = Redis::Stream::Client.new("test", "MANIFEST", 't2')
|
29
43
|
|
@@ -48,37 +62,51 @@ Timeout::timeout(10) do
|
|
48
62
|
end
|
49
63
|
```
|
50
64
|
|
51
|
-
####
|
65
|
+
#### Microservices example
|
52
66
|
|
53
67
|
1. Sinatra as a point of entry
|
54
|
-
|
68
|
+
``` http://127.0.0.1:4567?reverse=word```
|
69
|
+
2. Microservice for processing
|
55
70
|
|
56
71
|
# http.rb
|
57
72
|
```ruby
|
58
73
|
require 'sinatra'
|
59
|
-
require 'redis
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
74
|
+
require 'redis/stream'
|
75
|
+
|
76
|
+
class GreetingsApp < Sinatra::Base
|
77
|
+
configure do
|
78
|
+
set :inline_templates, true
|
79
|
+
set :redis_stream, Redis::Stream::Client.new("greetings", "HTTP", "http_client", "sync_start" => true, "caching" => false)
|
80
|
+
end
|
81
|
+
|
82
|
+
get '/' do
|
83
|
+
halt 500, 'reverse parameter not found' unless params.include?(:reverse)
|
84
|
+
result = settings.redis_stream.sync_add(params[:reverse], "group" => "GREETER", "time_out" => 60)
|
85
|
+
@reverse = params[:reverse]
|
86
|
+
@reversed = ''
|
87
|
+
@reversed = result['payload'] if result && result.include?('payload')
|
88
|
+
erb :index
|
89
|
+
end
|
70
90
|
end
|
71
91
|
|
92
|
+
GreetingsApp.run!
|
93
|
+
|
94
|
+
|
72
95
|
__END__
|
96
|
+
|
73
97
|
@@index
|
74
98
|
|
75
|
-
|
76
|
-
<
|
99
|
+
<!DOCTYPE html>
|
100
|
+
<head><title>Reverse Greeter</title></head>
|
101
|
+
<body>
|
102
|
+
<p><%= @reverse %> <=> <%= @reversed %></p>
|
103
|
+
</body>
|
104
|
+
</html>
|
77
105
|
```
|
78
106
|
|
79
107
|
# reverse_greeter.rb
|
80
108
|
```ruby
|
81
|
-
require 'redis
|
109
|
+
require 'redis/stream'
|
82
110
|
|
83
111
|
reverse_greeter = Redis::Stream::Client.new("greetings", "GREETER", "reverse_greeter")
|
84
112
|
reverse_greeter.on_message do |message|
|
data/config.yml
CHANGED
data/lib/redis/stream/client.rb
CHANGED
@@ -22,9 +22,11 @@ class Redis
|
|
22
22
|
# Example: Redis::Stream::Client.new("resolver", "stream", {"logger" => Logger.new(STDOUT)})
|
23
23
|
# if group is nil or not supplied then no rstream group will be setup
|
24
24
|
def initialize(stream_name, group_name = nil, name = rand(36 ** 7).to_s(36), options = {})
|
25
|
-
default_options = {"host" => "127.0.0.1", "port" => 6379, "db" => 0, "logger" => Logger.new(STDOUT)}
|
25
|
+
default_options = {"host" => "127.0.0.1", "port" => 6379, "db" => 0, "config_file_path" => '.', "logger" => Logger.new(STDOUT)}
|
26
26
|
options = default_options.merge(options)
|
27
27
|
|
28
|
+
Redis::Stream::Config.path = options['config_file_path']
|
29
|
+
|
28
30
|
host = options["host"]
|
29
31
|
port = options["port"]
|
30
32
|
db = options["db"]
|
@@ -36,8 +38,13 @@ class Redis
|
|
36
38
|
@stream = stream_name
|
37
39
|
@group = group_name
|
38
40
|
if options.include?('redis')
|
41
|
+
@logger.info("Taking REDIS as a parameter")
|
39
42
|
@redis = options['redis']
|
43
|
+
elsif Redis::Stream::Config.file_exists? && Redis::Stream::Config.include?(:redis)
|
44
|
+
@logger.info("Taking REDIS from config file")
|
45
|
+
@redis = Redis.new(Redis::Stream::Config[:redis])
|
40
46
|
else
|
47
|
+
@logger.info("Instantiating REDIS")
|
41
48
|
@redis = Redis.new(host: host, port: port, db: db)
|
42
49
|
end
|
43
50
|
@consumer_id = "#{@name}-#{@group}-#{Process.pid}"
|
data/lib/redis/stream/config.rb
CHANGED
@@ -6,6 +6,19 @@ class Redis
|
|
6
6
|
class Config
|
7
7
|
@config = {}
|
8
8
|
@config_file_path = ""
|
9
|
+
@config_file_name = 'config.yml'
|
10
|
+
|
11
|
+
#get name of config file
|
12
|
+
# @return [String] get name of config file
|
13
|
+
def self.name
|
14
|
+
@config_file_name
|
15
|
+
end
|
16
|
+
|
17
|
+
#set config file name defaults to config.yml
|
18
|
+
# @param [String] config_file_name Name of config file
|
19
|
+
def self.name=(config_file_name)
|
20
|
+
@config_file_name = config_file_name
|
21
|
+
end
|
9
22
|
|
10
23
|
# return the current location of the config.yml file
|
11
24
|
# @return [String] path of config.yml
|
@@ -34,7 +47,7 @@ class Redis
|
|
34
47
|
def self.[]=(key, value)
|
35
48
|
init
|
36
49
|
@config[key] = value
|
37
|
-
File.open("#{path}
|
50
|
+
File.open("#{path}/#{name}", 'w') do |f|
|
38
51
|
f.puts @config.to_yaml
|
39
52
|
end
|
40
53
|
end
|
@@ -53,19 +66,26 @@ class Redis
|
|
53
66
|
def self.init
|
54
67
|
discover_config_file_path
|
55
68
|
if @config.empty?
|
56
|
-
config = YAML::load_file("#{path}
|
69
|
+
config = YAML::load_file("#{path}/#{name}")
|
57
70
|
@config = process(config)
|
58
71
|
end
|
59
72
|
end
|
60
73
|
|
74
|
+
# check if config file is present on system
|
75
|
+
# @return [TrueClass, FalseClass]
|
76
|
+
def self.file_exists?
|
77
|
+
discover_config_file_path
|
78
|
+
File.exists?("#{path}/#{name}")
|
79
|
+
end
|
80
|
+
|
61
81
|
private
|
62
82
|
|
63
83
|
#determine location of config.yml file
|
64
84
|
def self.discover_config_file_path
|
65
85
|
if @config_file_path.nil? || @config_file_path.empty?
|
66
|
-
if File.exist?(
|
86
|
+
if File.exist?(name)
|
67
87
|
@config_file_path = '.'
|
68
|
-
elsif File.exist?("config
|
88
|
+
elsif File.exist?("config/#{name}")
|
69
89
|
@config_file_path = 'config'
|
70
90
|
end
|
71
91
|
end
|
data/lib/redis/stream/version.rb
CHANGED
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
|
+
version: 0.3.0
|
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-01-
|
11
|
+
date: 2020-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|