redis-queue 0.0.4 → 0.1.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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MzdlY2YzMGE2MmI5Mzc2ZDI5NjYwMjQ1NzQyMDRlMTY0NWJkZjM0ZA==
5
- data.tar.gz: !binary |-
6
- MzI5YjZiYmNjYTBhZjVkNjBkYzRjMTNmZDlkMzRhNzhmNDUzNWIyMg==
2
+ SHA256:
3
+ metadata.gz: 375d3e2d535e91e0a7e7297da4edfcb19e095354b96e55333c7f24fa7729fef6
4
+ data.tar.gz: 2a443a494c57981b7b655a828bae03e4b68e2b162b720ab90e28874d76ddd2b4
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MDQ2NTJkOTQ3MzQwMWZmNmI4ZDBjZjA5NTNjOWQ2NTgyNTAxZGEwZjA5OWNi
10
- MjU1ZWViMTU2MTI2MTU0MDk0N2VlMTIwOTU1OWQxYTdlZTFiMzA0YzM3NGUx
11
- MDczODJmYjI0ZTRhNWYxNjU0YzIyZmM1ZTY3OTdmM2ZkZmM2YWQ=
12
- data.tar.gz: !binary |-
13
- MGE0Nzk1Y2EyY2VjMTMzNDQxMzNjNDA4YzYyNWEzNWE4MmQ1NmZkNWUwMTE0
14
- NGRjMjM4MmQzZGVlMTZlODY5MzY5OTViOWM0YzUyMjIyM2E4YTMzMGE2ODMx
15
- MzMyYWQ5NzMyMDM3ZjliZDY1ZDVjNmEyOTlmMDcyNmY5N2U1ZTk=
6
+ metadata.gz: 92e754d76d4a38d22e5725ae97a97aa15b30a023d8274ac7f61b89261e1e0ef4eb4e6a07bbcb8ff86367ab9971c23f1c38a3bf7dada16b2c22a89f191a9ee4e1
7
+ data.tar.gz: 4b257132e995cc3b5f8e45d86752047d0c9dfae06a20b36d7388739292e71e8e413caad8282e3493f62144b55369a06756982848c05e9c99b7c5a391491509cf
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in redis-queue.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -31,15 +31,15 @@ queue << "a" # << is an alias of push
31
31
 
32
32
  # By default, calling pop method is a blocking operation
33
33
  # Your code will wait here for a new
34
- while message=@queue.pop
34
+ while message=queue.pop
35
35
  #Remove message from the backup queue if the message has been processed without errors
36
36
  queue.commit if YourTask.new(message).perform.succeed?
37
37
  end
38
38
 
39
39
  #Process messages using block
40
40
 
41
- @queue.process do |message|
42
- #@queue.commit is called if last statement of the block returns true
41
+ queue.process do |message|
42
+ #queue.commit is called if last statement of the block returns true
43
43
  YourTask.new(message).perform.succeed?
44
44
  end
45
45
 
data/Rakefile CHANGED
@@ -1,9 +1,11 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec) do |spec|
5
7
  spec.pattern = 'spec/*_spec.rb'
6
8
  end
7
9
 
8
- task :default => :spec
9
- task :test => :spec
10
+ task default: :spec
11
+ task test: :spec
@@ -1,25 +1,25 @@
1
- require "redis-queue"
2
- require "thread"
1
+ # frozen_string_literal: true
3
2
 
3
+ require 'redis-queue'
4
4
  redis = Redis.new
5
- #Create a queue that will listen for a new element for 10 seconds
6
- queue = Redis::Queue.new('__test', 'bp__test', :redis => redis, :timeout => 10)
7
- queue.clear true
5
+ # Create a queue that will listen for a new element for 10 seconds
6
+ queue = Redis::Queue.new('__test', 'bp__test', redis: redis, timeout: 10)
7
+ queue.clear true
8
8
 
9
9
  100.times { queue << rand(100) }
10
10
 
11
11
  # Simulate a delayed insert
12
12
  t = Thread.new do
13
13
  sleep 3
14
- # We should use a second connection here since the first one is busy
15
- # on a blocking call
16
- _redis = Redis.new
17
- _queue = Redis::Queue.new('__test', 'bp__test', :redis => _redis)
18
- 100.times { _queue << "e_#{rand(100)}" }
14
+ # We should use a second connection here since the first one is busy
15
+ # on a blocking call
16
+ other_redis = Redis.new
17
+ other_queue = Redis::Queue.new('__test', 'bp__test', redis: other_redis)
18
+ 100.times { other_queue << "e_#{rand(100)}" }
19
19
  end
20
20
 
21
- #When all elements are dequeud, process method will wait for 10 secods before exit
21
+ # When all elements are dequeud, process method will wait for 10 secods before exit
22
22
  queue.process do |message|
23
- puts "'#{message}'"
23
+ puts "'#{message}'"
24
24
  end
25
- t.join
25
+ t.join
@@ -1,10 +1,12 @@
1
- require "redis-queue"
1
+ # frozen_string_literal: true
2
+
3
+ require 'redis-queue'
2
4
 
3
5
  redis = Redis.new
4
6
 
5
- queue = Redis::Queue.new('__test', 'bp__test', :redis => redis)
7
+ queue = Redis::Queue.new('__test', 'bp__test', redis: redis)
6
8
  queue.clear true
7
9
 
8
10
  100.times { queue << rand(100) }
9
11
 
10
- queue.process(true) {|m| puts m}
12
+ queue.process(true) { |m| puts m }
@@ -1,3 +1,4 @@
1
- require "redis"
2
- require "redis/connection/hiredis"
3
- require "redis/queue"
1
+ # frozen_string_literal: true
2
+
3
+ require 'redis'
4
+ require 'redis/queue'
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Redis
2
4
  class Queue
3
-
4
- VERSION = "0.0.4"
5
+ VERSION = '0.1.0'
5
6
 
6
7
  def self.version
7
8
  "redis-queue version #{VERSION}"
@@ -10,7 +11,7 @@ class Redis
10
11
  def initialize(queue_name, process_queue_name, options = {})
11
12
  raise ArgumentError, 'First argument must be a non empty string' if !queue_name.is_a?(String) || queue_name.empty?
12
13
  raise ArgumentError, 'Second argument must be a non empty string' if !process_queue_name.is_a?(String) || process_queue_name.empty?
13
- raise ArgumentError, 'Queue and Process queue have the same name' if process_queue_name == queue_name
14
+ raise ArgumentError, 'Queue and Process queue have the same name' if process_queue_name == queue_name
14
15
 
15
16
  @redis = options[:redis] || Redis.current
16
17
  @queue_name = queue_name
@@ -29,19 +30,19 @@ class Redis
29
30
  end
30
31
 
31
32
  def empty?
32
- !(length > 0)
33
+ length <= 0
33
34
  end
34
35
 
35
36
  def push(obj)
36
37
  @redis.lpush(@queue_name, obj)
37
38
  end
38
39
 
39
- def pop(non_block=false)
40
- if non_block
41
- @last_message = @redis.rpoplpush(@queue_name,@process_queue_name)
42
- else
43
- @last_message = @redis.brpoplpush(@queue_name,@process_queue_name, @timeout)
44
- end
40
+ def pop(non_block = false)
41
+ @last_message = if non_block
42
+ @redis.rpoplpush(@queue_name, @process_queue_name)
43
+ else
44
+ @redis.brpoplpush(@queue_name, @process_queue_name, @timeout)
45
+ end
45
46
  @last_message
46
47
  end
47
48
 
@@ -49,7 +50,7 @@ class Redis
49
50
  @redis.lrem(@process_queue_name, 0, @last_message)
50
51
  end
51
52
 
52
- def process(non_block=false, timeout = nil)
53
+ def process(non_block = false, timeout = nil)
53
54
  @timeout = timeout unless timeout.nil?
54
55
  loop do
55
56
  message = pop(non_block)
@@ -57,20 +58,19 @@ class Redis
57
58
  commit if ret
58
59
  break if message.nil? || (non_block && empty?)
59
60
  end
60
-
61
61
  end
62
62
 
63
63
  def refill
64
- while message=@redis.lpop(@process_queue_name)
64
+ while (message = @redis.lpop(@process_queue_name))
65
65
  @redis.rpush(@queue_name, message)
66
66
  end
67
67
  true
68
68
  end
69
69
 
70
- alias :size :length
71
- alias :dec :pop
72
- alias :shift :pop
73
- alias :enc :push
74
- alias :<< :push
70
+ alias size length
71
+ alias dec pop
72
+ alias shift pop
73
+ alias enc push
74
+ alias << push
75
75
  end
76
- end
76
+ end
@@ -1,31 +1,31 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "redis-queue"
2
+ # frozen_string_literal: true
3
+
4
+ require File.expand_path('lib/redis/queue', __dir__)
4
5
 
5
6
  Gem::Specification.new do |s|
6
- s.name = "redis-queue"
7
+ s.name = 'redis-queue'
7
8
  s.version = Redis::Queue::VERSION
8
- s.authors = ["Francesco Laurita"]
9
- s.email = ["francesco.laurita@gmail.com"]
10
- s.homepage = "https://github.com/taganaka/redis-queue"
11
- s.summary = %q{A distributed queue based on Redis}
12
- s.description = %q{
9
+ s.authors = ['Francesco Laurita']
10
+ s.email = ['francesco.laurita@gmail.com']
11
+ s.homepage = 'https://github.com/taganaka/redis-queue'
12
+ s.summary = 'A distributed queue based on Redis'
13
+ s.description = '
13
14
  Adds Redis::Queue class which can be used as Distributed-Queue based on Redis.
14
15
  Redis is often used as a messaging server to implement processing of background jobs or other kinds of messaging tasks.
15
16
  It implements Reliable-queue pattern decribed here: http://redis.io/commands/rpoplpush
16
- }
17
+ '
17
18
 
18
- s.licenses = ["MIT"]
19
+ s.licenses = ['MIT']
19
20
 
20
- s.rubyforge_project = "redis-queue"
21
+ s.rubyforge_project = 'redis-queue'
21
22
 
22
23
  s.files = `git ls-files`.split("\n")
23
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
- s.require_paths = ["lib"]
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
26
+ s.require_paths = ['lib']
26
27
 
27
- s.add_runtime_dependency 'redis', '~> 3.0', '>= 3.0.4'
28
- s.add_runtime_dependency 'hiredis', '~> 0.5', '>= 0.5.2'
28
+ s.add_runtime_dependency 'redis', '>= 3.3.5', '< 5'
29
29
 
30
30
  s.add_development_dependency 'rspec', '~> 2.13', '>= 2.13.0'
31
31
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
- require "timeout"
4
+ require 'timeout'
3
5
 
4
6
  describe Redis::Queue do
5
7
  before(:all) do
6
8
  @redis = Redis.new
7
9
  @queue = Redis::Queue.new('__test', 'bp__test')
8
- @queue.clear true
10
+ @queue.clear true
9
11
  end
10
12
 
11
13
  after(:all) do
@@ -22,16 +24,16 @@ describe Redis::Queue do
22
24
  end
23
25
 
24
26
  it 'should add an element to the queue' do
25
- @queue << "a"
27
+ @queue << 'a'
26
28
  @queue.size.should be == 1
27
29
  end
28
30
 
29
31
  it 'should return an element from the queue' do
30
32
  message = @queue.pop(true)
31
- message.should be == "a"
33
+ message.should be == 'a'
32
34
  end
33
35
 
34
- it 'should remove the element from bp_queue if commit is called' do
36
+ it 'should remove the element from bp_queue if commit is called' do
35
37
  @redis.llen('bp__test').should be == 1
36
38
  @queue.commit
37
39
  @redis.llen('bp__test').should be == 0
@@ -39,17 +41,17 @@ describe Redis::Queue do
39
41
 
40
42
  it 'should implements fifo pattern' do
41
43
  @queue.clear
42
- payload = %w(a b c d e)
43
- payload.each {|e| @queue << e}
44
+ payload = %w[a b c d e]
45
+ payload.each { |e| @queue << e }
44
46
  test = []
45
- while e=@queue.pop(true)
47
+ while (e = @queue.pop(true))
46
48
  test << e
47
49
  end
48
50
  payload.should be == test
49
51
  end
50
52
 
51
53
  it 'should remove all of the elements from the main queue' do
52
- %w(a b c d e).each {|e| @queue << e}
54
+ %w[a b c d e].each { |e| @queue << e }
53
55
  @queue.size.should be > 0
54
56
  @queue.pop(true)
55
57
  @queue.clear
@@ -62,25 +64,25 @@ describe Redis::Queue do
62
64
  end
63
65
 
64
66
  it 'should prcess a message' do
65
- @queue << "a"
66
- @queue.process(true){|m|m.should be == "a"; true}
67
+ @queue << 'a'
68
+ @queue.process(true) { |m| m.should be == 'a'; true }
67
69
  end
68
70
 
69
71
  it 'should prcess a message leaving it into the bp_queue' do
70
- @queue << "a"
71
- @queue << "a"
72
- @queue.process(true){|m|m.should be == "a"; false}
73
- @redis.lrange('bp__test',0, -1).should be == ['a', 'a']
72
+ @queue << 'a'
73
+ @queue << 'a'
74
+ @queue.process(true) { |m| m.should be == 'a'; false }
75
+ @redis.lrange('bp__test', 0, -1).should be == %w[a a]
74
76
  end
75
77
 
76
78
  it 'should refill a main queue' do
77
79
  @queue.clear(true)
78
- @queue << "a"
79
- @queue << "a"
80
- @queue.process(true){|m|m.should be == "a"; false}
81
- @redis.lrange('bp__test',0, -1).should be == ['a', 'a']
80
+ @queue << 'a'
81
+ @queue << 'a'
82
+ @queue.process(true) { |m| m.should be == 'a'; false }
83
+ @redis.lrange('bp__test', 0, -1).should be == %w[a a]
82
84
  @queue.refill
83
- @redis.lrange('__test',0, -1).should be == ['a', 'a']
85
+ @redis.lrange('__test', 0, -1).should be == %w[a a]
84
86
  @redis.llen('bp__test').should be == 0
85
87
  end
86
88
 
@@ -89,32 +91,30 @@ describe Redis::Queue do
89
91
  2.times { @queue << rand(100) }
90
92
  is_ok = true
91
93
  begin
92
- Timeout::timeout(3) {
93
- @queue.process(false, 2) {|m| true}
94
- }
95
- rescue Timeout::Error => e
94
+ Timeout.timeout(3) do
95
+ @queue.process(false, 2) { |_m| true }
96
+ end
97
+ rescue Timeout::Error => _e
96
98
  is_ok = false
97
99
  end
98
-
99
- is_ok.should be_true
100
100
 
101
+ is_ok.should be_truthy
101
102
  end
102
103
 
103
104
  it 'should honor the timeout param in the initializer' do
104
105
  redis = Redis.new
105
- queue = Redis::Queue.new('__test_tm', 'bp__test_tm', :redis => redis, :timeout => 2)
106
+ queue = Redis::Queue.new('__test_tm', 'bp__test_tm', redis: redis, timeout: 2)
106
107
  queue.clear true
107
108
 
108
109
  is_ok = true
109
110
  begin
110
- Timeout::timeout(4) {
111
+ Timeout.timeout(4) do
111
112
  queue.pop
112
- }
113
- rescue Timeout::Error => e
113
+ end
114
+ rescue Timeout::Error => _e
114
115
  is_ok = false
115
116
  end
116
117
  queue.clear
117
- is_ok.should be_true
118
+ is_ok.should be_truthy
118
119
  end
119
-
120
- end
120
+ end
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler'
3
5
  require 'rspec'
4
6
 
5
-
6
7
  RSpec.configure do |config|
7
- config.color_enabled = true
8
+ config.color = true
8
9
  end
9
10
 
10
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
11
- require 'redis-queue'
11
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
12
+ require 'redis-queue'
metadata CHANGED
@@ -1,76 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Laurita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-24 00:00:00.000000000 Z
11
+ date: 2018-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
20
- - - ! '>='
19
+ version: 3.3.5
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 3.0.4
22
+ version: '5'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ~>
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '3.0'
30
- - - ! '>='
29
+ version: 3.3.5
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 3.0.4
33
- - !ruby/object:Gem::Dependency
34
- name: hiredis
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ~>
38
- - !ruby/object:Gem::Version
39
- version: '0.5'
40
- - - ! '>='
41
- - !ruby/object:Gem::Version
42
- version: 0.5.2
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ~>
48
- - !ruby/object:Gem::Version
49
- version: '0.5'
50
- - - ! '>='
51
- - !ruby/object:Gem::Version
52
- version: 0.5.2
32
+ version: '5'
53
33
  - !ruby/object:Gem::Dependency
54
34
  name: rspec
55
35
  requirement: !ruby/object:Gem::Requirement
56
36
  requirements:
57
- - - ~>
37
+ - - "~>"
58
38
  - !ruby/object:Gem::Version
59
39
  version: '2.13'
60
- - - ! '>='
40
+ - - ">="
61
41
  - !ruby/object:Gem::Version
62
42
  version: 2.13.0
63
43
  type: :development
64
44
  prerelease: false
65
45
  version_requirements: !ruby/object:Gem::Requirement
66
46
  requirements:
67
- - - ~>
47
+ - - "~>"
68
48
  - !ruby/object:Gem::Version
69
49
  version: '2.13'
70
- - - ! '>='
50
+ - - ">="
71
51
  - !ruby/object:Gem::Version
72
52
  version: 2.13.0
73
- description: ! "\n Adds Redis::Queue class which can be used as Distributed-Queue
53
+ description: "\n Adds Redis::Queue class which can be used as Distributed-Queue
74
54
  based on Redis.\n Redis is often used as a messaging server to implement processing
75
55
  of background jobs or other kinds of messaging tasks.\n It implements Reliable-queue
76
56
  pattern decribed here: http://redis.io/commands/rpoplpush\n "
@@ -80,7 +60,7 @@ executables: []
80
60
  extensions: []
81
61
  extra_rdoc_files: []
82
62
  files:
83
- - .gitignore
63
+ - ".gitignore"
84
64
  - Gemfile
85
65
  - LICENSE.txt
86
66
  - README.md
@@ -102,21 +82,20 @@ require_paths:
102
82
  - lib
103
83
  required_ruby_version: !ruby/object:Gem::Requirement
104
84
  requirements:
105
- - - ! '>='
85
+ - - ">="
106
86
  - !ruby/object:Gem::Version
107
87
  version: '0'
108
88
  required_rubygems_version: !ruby/object:Gem::Requirement
109
89
  requirements:
110
- - - ! '>='
90
+ - - ">="
111
91
  - !ruby/object:Gem::Version
112
92
  version: '0'
113
93
  requirements: []
114
94
  rubyforge_project: redis-queue
115
- rubygems_version: 2.2.2
95
+ rubygems_version: 2.7.2
116
96
  signing_key:
117
97
  specification_version: 4
118
98
  summary: A distributed queue based on Redis
119
99
  test_files:
120
100
  - spec/redis_queue_spec.rb
121
101
  - spec/spec_helper.rb
122
- has_rdoc: