redis-stream 0.2.0 → 0.3.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: 39b625a413edc217bd17ecda0c8f6dc899507cdc0535169d464210c2cd3d891b
4
- data.tar.gz: d3ae887d8623687c190672a30bed816158e3fc043c33d2aa2b1488bcae653541
3
+ metadata.gz: 7e636f1c98003bb96c0ca288b66e7ec9e8a32232a2eb1a06c3c5291df97bed4b
4
+ data.tar.gz: d9e9533cc0175ceb705d4f9d9964f5fb5f94c517df3bd3cd5614c12dc2962c76
5
5
  SHA512:
6
- metadata.gz: 163921136b188cd050a536bd3b6f7023401a2c41aae19d6bf5061ac5bb926e1d92a46799fb1868de8f3ddbb2f80817d80b9d7976a684e225b4d4eaf7e1d0afad
7
- data.tar.gz: 5d6cb36afb6089e13775e7119c7bd453c78fe6aeba9e39a423c41b3ad06e312e8b6db5c5744034341bb69fdd440090882c26598f48421838017a1e10a5cfb0e4
6
+ metadata.gz: b900b2614e55c5a470cf1b54f0751475c4186a9a1272bd1d0acefb0a9827139ed34d4e857494396333a2ff4c0f4556050df7400316f236502a4261f2916aab05
7
+ data.tar.gz: cf969f706a177b0636f0100909987fc52fee799b502accae266a697524068d77ce9d12919b9bc80dda6acaa055d6ef9532a85b183fcfa0c0333ff55f0d89a507
data/.travis.yml CHANGED
@@ -1,7 +1,10 @@
1
1
  ---
2
- sudo: false
2
+ os: linux
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.5.0
6
+ - 2.5
7
+ - jruby
8
+ services:
9
+ - redis
7
10
  before_install: gem install bundler -v 2.0.1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redis-stream (0.2.0)
4
+ redis-stream (0.3.0)
5
5
  moneta (~> 1.2)
6
6
  multi_json (~> 1.14)
7
7
  redis (= 4.1.3)
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-stream'
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
- #### Micro services example
65
+ #### Microservices example
52
66
 
53
67
  1. Sinatra as a point of entry
54
- 2. microservice for processing
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-stream'
60
-
61
- configure do
62
- set :redis_stream, Redis::Stream::Client.new("greetings", "HTTP", "http_client", "sync_start" => true)
63
-
64
- get '/:name' do
65
- halt 500, 'name parameter not found' unless params.include?(:name)
66
- result = settings.redis_stream.sync_add(params[:name], "group" => "GREETER", "time_out" => 60)
67
- @name = params[:name]
68
- @reversed_name = result[payload]
69
- erb :index
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
- <p>Hello, <%= @name %>!</p>
76
- <p><%= @reversed_name</p>
99
+ <!DOCTYPE html>
100
+ <head><title>Reverse Greeter</title></head>
101
+ <body>
102
+ <p><%= @reverse %> &lt;=&gt; <%= @reversed %></p>
103
+ </body>
104
+ </html>
77
105
  ```
78
106
 
79
107
  # reverse_greeter.rb
80
108
  ```ruby
81
- require 'redis-stream'
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
@@ -1 +1,3 @@
1
- data_cache: "/Users/mehmetc/Tmp/resolver/data_cache"
1
+ data_cache: "/Users/mehmetc/Tmp/resolver/data_cache"
2
+ redis:
3
+ url: "redis://127.0.0.1:7000/0"
@@ -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}"
@@ -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}/config.yml", 'w') do |f|
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}/config.yml")
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?('config.yml')
86
+ if File.exist?(name)
67
87
  @config_file_path = '.'
68
- elsif File.exist?("config/config.yml")
88
+ elsif File.exist?("config/#{name}")
69
89
  @config_file_path = 'config'
70
90
  end
71
91
  end
@@ -1,6 +1,6 @@
1
1
  #encoding: UTF-8
2
2
  class Redis
3
3
  module Stream
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
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.2.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-23 00:00:00.000000000 Z
11
+ date: 2020-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler