turnpike 0.3.2 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +1 -0
- data/README.md +4 -11
- data/lib/turnpike/queue.rb +9 -26
- data/lib/turnpike/version.rb +1 -1
- data/lib/turnpike.rb +1 -1
- data/test/turnpike_test.rb +27 -22
- metadata +10 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5cc33fb8535559daf70d3901bc2099644bc291b6
|
4
|
+
data.tar.gz: 0a3fd6e3d12dfbbdbf450252eee59b6e31c2c1a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0ea35fe014cf3829a24677a7ab481e58b399355c04661581c2e300c0bc31edf877cf7f6c093df2f0a98ccfeb08477c2d21eee95d907df8151a12be24595fe1ac
|
7
|
+
data.tar.gz: 8a46a54abc67b7ea943f66425d46ccd6825db44e46f4a18fc7b20aa11453b837b3c2704ac17f91e4bdf1fbc1279134dbddbc9d1fa0ec2e6e5e05dbf4624e12c4
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|
[![travis][1]][2]
|
4
4
|
|
5
|
-
Turnpike
|
6
|
-
colloquial.
|
5
|
+
Turnpike wraps a [Redis List][4] and speaks Ruby colloquial.
|
7
6
|
|
8
7
|
![turnpike][3]
|
9
8
|
|
@@ -11,22 +10,16 @@ colloquial.
|
|
11
10
|
|
12
11
|
```ruby
|
13
12
|
queue = Turnpike['foo']
|
14
|
-
|
15
13
|
queue << 1, 2, 3
|
16
14
|
queue.pop # => 1
|
17
|
-
queue.peek # => [2, 3]
|
18
|
-
|
19
15
|
queue << 4
|
20
|
-
queue.
|
21
|
-
|
22
|
-
queue.unshift 1
|
23
|
-
queue.peek # => [1, 2, 3, 4]
|
16
|
+
queue.unshift(1)
|
17
|
+
queue.pop(4) # => [1, 2, 3, 4]
|
24
18
|
```
|
25
19
|
|
26
|
-
|
20
|
+
Turnpike requires Redis 2.4 or higher.
|
27
21
|
|
28
22
|
[1]: https://secure.travis-ci.org/hakanensari/turnpike.png
|
29
23
|
[2]: http://travis-ci.org/hakanensari/turnpike
|
30
24
|
[3]: http://f.cl.ly/items/33242X323P3M1t1G400H/turnpike.jpg
|
31
25
|
[4]: http://redis.io/topics/data-types
|
32
|
-
[5]: https://github.com/hakanensari/turnpike/blob/master/lib/turnpike/queue.rb
|
data/lib/turnpike/queue.rb
CHANGED
@@ -4,18 +4,18 @@ module Turnpike
|
|
4
4
|
# Returns a String name.
|
5
5
|
attr :name
|
6
6
|
|
7
|
-
#
|
7
|
+
# Create a new queue.
|
8
8
|
#
|
9
9
|
# name - A queue name that responds to to_s.
|
10
10
|
def initialize(name = 'queue')
|
11
11
|
@name = "turnpike:#{name}"
|
12
12
|
end
|
13
13
|
|
14
|
-
#
|
14
|
+
# Remove all items from the queue.
|
15
15
|
#
|
16
16
|
# Returns Integer number of items that were removed.
|
17
17
|
def clear
|
18
|
-
redis.del
|
18
|
+
redis.del(name)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Returns whether the queue is empty.
|
@@ -23,11 +23,6 @@ module Turnpike
|
|
23
23
|
size == 0
|
24
24
|
end
|
25
25
|
|
26
|
-
# Return an Array of all queued items.
|
27
|
-
def peek
|
28
|
-
redis.lrange(name, 0, -1).map { |i| Marshal.load i }
|
29
|
-
end
|
30
|
-
|
31
26
|
# Pops one or more items from the front of the queue.
|
32
27
|
#
|
33
28
|
# n - Integer number of items to pop.
|
@@ -43,17 +38,13 @@ module Turnpike
|
|
43
38
|
n == 1 ? items.first : items
|
44
39
|
end
|
45
40
|
|
46
|
-
#
|
41
|
+
# Push items to the end of the queue.
|
47
42
|
#
|
48
43
|
# items - A splat Array of items.
|
49
44
|
#
|
50
45
|
# Returns the Integer size of the queue after the operation.
|
51
46
|
def push(*items)
|
52
|
-
|
53
|
-
redis.rpush name, items.map { |i| Marshal.dump i }
|
54
|
-
else
|
55
|
-
items.each { |i| redis.rpush name, Marshal.dump(i) }
|
56
|
-
end
|
47
|
+
redis.rpush(name, items.map { |i| Marshal.dump(i) })
|
57
48
|
end
|
58
49
|
|
59
50
|
# Syntactic sugar.
|
@@ -61,30 +52,22 @@ module Turnpike
|
|
61
52
|
|
62
53
|
# Returns the Integer size of the queue.
|
63
54
|
def size
|
64
|
-
redis.llen
|
55
|
+
redis.llen(name)
|
65
56
|
end
|
66
57
|
|
67
|
-
#
|
58
|
+
# Push items to the front of the queue.
|
68
59
|
#
|
69
60
|
# items - A splat Array of items.
|
70
61
|
#
|
71
62
|
# Returns the Integer size of the queue after the operation.
|
72
63
|
def unshift(*items)
|
73
|
-
|
74
|
-
redis.lpush name, items.map { |i| Marshal.dump i }
|
75
|
-
else
|
76
|
-
items.each { |i| redis.lpush name, Marshal.dump(i) }
|
77
|
-
end
|
64
|
+
redis.lpush(name, items.map { |i| Marshal.dump(i) })
|
78
65
|
end
|
79
66
|
|
80
67
|
private
|
81
68
|
|
82
69
|
def redis
|
83
|
-
Redis.current ||= Redis.connect
|
84
|
-
end
|
85
|
-
|
86
|
-
def redis_version
|
87
|
-
@redis_version ||= redis.info['redis_version']
|
70
|
+
Redis.current ||= Redis.connect(Turnpike.options)
|
88
71
|
end
|
89
72
|
end
|
90
73
|
end
|
data/lib/turnpike/version.rb
CHANGED
data/lib/turnpike.rb
CHANGED
data/test/turnpike_test.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
require 'bundler/setup'
|
2
|
-
require '
|
2
|
+
require 'minitest/autorun'
|
3
3
|
require File.expand_path('../lib/turnpike', File.dirname(__FILE__))
|
4
4
|
|
5
|
-
class TestTurnpike <
|
5
|
+
class TestTurnpike < MiniTest::Unit::TestCase
|
6
6
|
def setup
|
7
7
|
Redis.current.flushall
|
8
8
|
end
|
9
9
|
|
10
|
+
def peek(queue)
|
11
|
+
redis = queue.send(:redis)
|
12
|
+
redis.lrange(queue.name, 0, -1).map { |i| Marshal.load(i) }
|
13
|
+
end
|
14
|
+
|
10
15
|
def test_bracket
|
11
16
|
queue = Turnpike['foo']
|
12
17
|
assert_kind_of Turnpike::Queue, queue
|
@@ -24,41 +29,41 @@ class TestTurnpike < Test::Unit::TestCase
|
|
24
29
|
|
25
30
|
def test_push
|
26
31
|
queue = Turnpike::Queue.new
|
27
|
-
queue.push
|
32
|
+
queue.push(1)
|
28
33
|
assert_equal 1, queue.size
|
29
|
-
queue.push
|
34
|
+
queue.push(2, 3)
|
30
35
|
assert_equal 3, queue.size
|
31
|
-
assert_equal [1, 2, 3], queue
|
36
|
+
assert_equal [1, 2, 3], peek(queue)
|
32
37
|
end
|
33
38
|
|
34
39
|
def test_push_2_2
|
35
40
|
queue = Turnpike::Queue.new
|
36
41
|
queue.instance_variable_set :@redis_version, '2.2'
|
37
|
-
queue.push
|
38
|
-
queue.push
|
39
|
-
assert_equal [1, 2, 3], queue
|
42
|
+
queue.push(1)
|
43
|
+
queue.push(2, 3)
|
44
|
+
assert_equal [1, 2, 3], peek(queue)
|
40
45
|
end
|
41
46
|
|
42
47
|
def test_unshift
|
43
48
|
queue = Turnpike::Queue.new
|
44
|
-
queue.unshift
|
49
|
+
queue.unshift(1)
|
45
50
|
assert_equal 1, queue.size
|
46
|
-
queue.unshift
|
51
|
+
queue.unshift(2, 3)
|
47
52
|
assert_equal 3, queue.size
|
48
|
-
assert_equal [3, 2, 1], queue
|
53
|
+
assert_equal [3, 2, 1], peek(queue)
|
49
54
|
end
|
50
55
|
|
51
56
|
def test_unshift_2_2
|
52
57
|
queue = Turnpike::Queue.new
|
53
58
|
queue.instance_variable_set :@redis_version, '2.2'
|
54
|
-
queue.unshift
|
55
|
-
queue.unshift
|
56
|
-
assert_equal [3, 2, 1], queue
|
59
|
+
queue.unshift(1)
|
60
|
+
queue.unshift(2, 3)
|
61
|
+
assert_equal [3, 2, 1], peek(queue)
|
57
62
|
end
|
58
63
|
|
59
64
|
def test_pop
|
60
65
|
queue = Turnpike::Queue.new
|
61
|
-
queue.push
|
66
|
+
queue.push(1, 2)
|
62
67
|
assert_equal 1, queue.pop
|
63
68
|
assert_equal 2, queue.pop
|
64
69
|
assert_equal nil, queue.pop
|
@@ -66,7 +71,7 @@ class TestTurnpike < Test::Unit::TestCase
|
|
66
71
|
|
67
72
|
def test_pop_many
|
68
73
|
queue = Turnpike::Queue.new
|
69
|
-
queue.push
|
74
|
+
queue.push(1, 2, 3)
|
70
75
|
assert_equal [1, 2], queue.pop(2)
|
71
76
|
assert_equal [3], queue.pop(2)
|
72
77
|
assert_equal [], queue.pop(2)
|
@@ -74,8 +79,8 @@ class TestTurnpike < Test::Unit::TestCase
|
|
74
79
|
|
75
80
|
def test_order
|
76
81
|
queue = Turnpike::Queue.new
|
77
|
-
queue.push
|
78
|
-
queue.unshift
|
82
|
+
queue.push(1, 2)
|
83
|
+
queue.unshift(3)
|
79
84
|
assert_equal 3, queue.pop
|
80
85
|
assert_equal 1, queue.pop
|
81
86
|
assert_equal 2, queue.pop
|
@@ -84,16 +89,16 @@ class TestTurnpike < Test::Unit::TestCase
|
|
84
89
|
def test_multiple_queues
|
85
90
|
queue1 = Turnpike::Queue.new 'foo'
|
86
91
|
queue2 = Turnpike::Queue.new 'bar'
|
87
|
-
queue1.push
|
88
|
-
queue2.push
|
92
|
+
queue1.push(1)
|
93
|
+
queue2.push(2, 3)
|
89
94
|
assert_equal 1, queue1.size
|
90
95
|
assert_equal 2, queue2.size
|
91
96
|
end
|
92
97
|
|
93
98
|
def test_peek
|
94
99
|
queue = Turnpike::Queue.new
|
95
|
-
assert_equal [], queue
|
100
|
+
assert_equal [], peek(queue)
|
96
101
|
queue << 1
|
97
|
-
assert_equal [1], queue
|
102
|
+
assert_equal [1], peek(queue)
|
98
103
|
end
|
99
104
|
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turnpike
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Hakan Ensari
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-03-28 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: redis
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,17 +27,15 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Turnpike is a Redis-backed queue.
|
@@ -63,33 +58,27 @@ files:
|
|
63
58
|
- turnpike.gemspec
|
64
59
|
homepage: http://github.com/hakanensari/turnpike
|
65
60
|
licenses: []
|
61
|
+
metadata: {}
|
66
62
|
post_install_message:
|
67
63
|
rdoc_options: []
|
68
64
|
require_paths:
|
69
65
|
- lib
|
70
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
67
|
requirements:
|
73
|
-
- -
|
68
|
+
- - '>='
|
74
69
|
- !ruby/object:Gem::Version
|
75
70
|
version: '0'
|
76
|
-
segments:
|
77
|
-
- 0
|
78
|
-
hash: 3840254104933730285
|
79
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
72
|
requirements:
|
82
|
-
- -
|
73
|
+
- - '>='
|
83
74
|
- !ruby/object:Gem::Version
|
84
75
|
version: '0'
|
85
|
-
segments:
|
86
|
-
- 0
|
87
|
-
hash: 3840254104933730285
|
88
76
|
requirements: []
|
89
77
|
rubyforge_project:
|
90
|
-
rubygems_version:
|
78
|
+
rubygems_version: 2.0.0
|
91
79
|
signing_key:
|
92
|
-
specification_version:
|
80
|
+
specification_version: 4
|
93
81
|
summary: A Redis-backed queue
|
94
82
|
test_files:
|
95
83
|
- test/turnpike_test.rb
|
84
|
+
has_rdoc:
|