redis-unique-queue 2.0 → 2.1

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
- SHA1:
3
- metadata.gz: de78d99306d017bd477d116439e987481571fcbc
4
- data.tar.gz: 313940b8fe19ff797910d5b9fb0997d4e08879f7
2
+ SHA256:
3
+ metadata.gz: 0cb483775f4af126cde2e3d713746aae13a4e1580605eac7e35cee912d474499
4
+ data.tar.gz: f3aad7a84f8d9fb52f3d11943d044e7708b3a1cbb4df4fff5f4d98c694454b5f
5
5
  SHA512:
6
- metadata.gz: 1f918cd173c15ea8d164aa6f7ac277752701d2af2c6e90bfbd5876b12630445ee2453a8260e449ce8fc3c779514f8a279d5c543af16fb35da550eca34827402d
7
- data.tar.gz: 4f48d23ef3510e98e76cc8270c4cda303ffa8749c185767a7055b56c74130cac10abd4a3df27cc8d7b1f7b2ab7e59e64ee816d7af706d230f11f84aba1a5a178
6
+ metadata.gz: db94ba49aa4af8ac5115c8c4f10f6abae2f42014474922673118e15d4f90e23b4e3e5aef50221e0d5645635762856fd8003b6ae11259d476e120d544b0f57ba7
7
+ data.tar.gz: 670f8db02edc5ed5b43a1215492f8a80db8500cce66ce3927ae70452f40f699a254c26d92a492516cf97d6b151773c9b90e29d27061001b592dce654f9bcf2e1
data/README.md CHANGED
@@ -123,6 +123,14 @@ q.peek 23 #read the item at index 23
123
123
  q.peek 10, 5 #peek at five items starting at index 10
124
124
  ```
125
125
 
126
+ You can also peek into arbitrary ranges in the queue in reverse order.
127
+
128
+ ```ruby
129
+ q.peek_reverse 0 #read the last item in the queue
130
+ q.peek_reverse 7 #read the item at index 7 starting at the end of the queue
131
+ q.peek_reverse 2, 5 #peek at five items starting at index 2 in reverse order
132
+ ```
133
+
126
134
  The queue can be cleared of all items
127
135
  ```ruby
128
136
  q.clear
@@ -3,7 +3,7 @@ require "redis"
3
3
  class RedisUniqueQueue
4
4
  attr_reader :name
5
5
 
6
- VERSION = "2.0"
6
+ VERSION = "2.1"
7
7
 
8
8
  class InvalidNameException < StandardError; end;
9
9
  class InvalidRedisConfigException < StandardError; end;
@@ -82,6 +82,10 @@ class RedisUniqueQueue
82
82
  with { |redis| redis.zrange name, index, index + amount - 1 }
83
83
  end
84
84
 
85
+ def peek_reverse index, amount = 1
86
+ with { |redis| redis.zrevrange name, index, index + amount - 1 }
87
+ end
88
+
85
89
  def include? data
86
90
  !with { |redis| redis.zscore(name, data).nil? }
87
91
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "bundler", "~> 2.1.4"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_runtime_dependency 'redis'
24
24
  end
@@ -120,6 +120,25 @@ describe RedisUniqueQueue do
120
120
  expect(queue.peek(1,2)).to eq(%w(b c))
121
121
  expect(queue.peek(1,3)).to eq(%w(b c))
122
122
 
123
+ expect(queue.size).to eq(3)
124
+ expect(queue.all).to eq(%w(a b c))
125
+ end
126
+ end
127
+
128
+ describe '#peek_reverse' do
129
+ it 'allows you to peek at items in the queue in reverse order without mutating the queue' do
130
+ expect(queue.peek_reverse(0,1)).to eq(%w(c))
131
+ expect(queue.peek_reverse(1,1)).to eq(%w(b))
132
+ expect(queue.peek_reverse(2,1)).to eq(%w(a))
133
+ expect(queue.peek_reverse(3,1)).to eq([])
134
+
135
+ expect(queue.peek_reverse(0,2)).to eq(%w(c b))
136
+ expect(queue.peek_reverse(0,3)).to eq(%w(c b a))
137
+ expect(queue.peek_reverse(0,4)).to eq(%w(c b a))
138
+
139
+ expect(queue.peek_reverse(1,2)).to eq(%w(b a))
140
+ expect(queue.peek_reverse(1,3)).to eq(%w(b a))
141
+
123
142
  expect(queue.size).to eq(3)
124
143
  expect(queue.all).to eq(%w(a b c))
125
144
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-unique-queue
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.0'
4
+ version: '2.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Misha Conway
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-30 00:00:00.000000000 Z
11
+ date: 2020-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: 2.1.4
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: 2.1.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -87,8 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubyforge_project:
91
- rubygems_version: 2.6.14
90
+ rubygems_version: 3.0.8
92
91
  signing_key:
93
92
  specification_version: 4
94
93
  summary: A unique queue with atomic operations implemented in Redis