celluloid-redis 0.0.1

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.
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service-name: travis-pro
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format documentation
3
+ --backtrace
4
+ --default_path spec
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - ruby-head
5
+ - jruby-19mode
6
+ - rbx-19mode
7
+ - jruby-head
8
+
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: 2.0.0
12
+ - rvm: ruby-head
13
+ - rvm: jruby-head
14
+ - rvm: rbx-19mode
15
+
16
+ notifications:
17
+ irc: "irc.freenode.org#celluloid"
data/CHANGES.md ADDED
@@ -0,0 +1,3 @@
1
+ 0.0.1
2
+ -----
3
+ * Initial (pre-)release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'coveralls', require: false
5
+ gem 'celluloid', github: 'celluloid/celluloid'
6
+ gem 'celluloid-io', github: 'celluloid/celluloid-io'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tony Arcieri
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ Celluloid::Redis
2
+ ================
3
+ [![Build Status](https://secure.travis-ci.org/celluloid/celluloid-redis.png?branch=master)](http://travis-ci.org/celluloid/celluloid-redis)
4
+ [![Dependency Status](https://gemnasium.com/celluloid/celluloid-redis.png)](https://gemnasium.com/celluloid/celluloid-redis)
5
+ [![Code Climate](https://codeclimate.com/github/celluloid/celluloid-redis.png)](https://codeclimate.com/github/celluloid/celluloid-redis)
6
+ [![Coverage Status](https://coveralls.io/repos/celluloid/celluloid-redis/badge.png?branch=master)](https://coveralls.io/r/celluloid/celluloid-redis)
7
+
8
+ A [Celluloid::IO][celluloidio]-based connection backend for the
9
+ [redis-rb][redisrb] gem, providing "evented" connection support that can
10
+ multiplex long-lived blocking calls like pub/sub and blpop(rpush) with the
11
+ Celluloid message protocol.
12
+
13
+ [celluloidio]: https://github.com/celluloid/celluloid-io
14
+ [redisrb]: https://github.com/redis/redis-rb
15
+
16
+ ## Why?
17
+
18
+ Unlike EventMachine, Celluloid::IO ideally does not need to provide separate
19
+ "Celluloid-enabled" versions of each and every library that ever does any kind
20
+ of I/O, but can instead leverage dependency injection APIs that tell libraries
21
+ to use `Celluloid::IO::TCPSocket` instead of `TCPSocket`.
22
+
23
+ Unfortunately, the `redis-rb` gem is a bit gnarly and does a lot of strange
24
+ things like monkeypatching its own subclasses of `TCPSocket` and `UNIXSocket`
25
+ in attempts to add better timeout handling.
26
+
27
+ Rather than trying to inject itself into that mess, this gem provides
28
+ `Redis::Connection::Celluloid` which seeks to be a drop-in replacement for
29
+ `Redis::Connection::Ruby`.
30
+
31
+ ## Installation
32
+
33
+ Add this line to your application's Gemfile:
34
+
35
+ gem 'celluloid-redis'
36
+
37
+ And then execute:
38
+
39
+ $ bundle
40
+
41
+ Or install it yourself as:
42
+
43
+ $ gem install celluloid-redis
44
+
45
+ Require it in your Ruby application with:
46
+
47
+ require 'celluloid/redis'
48
+
49
+ ## Usage
50
+
51
+ When instantiating the client object, specify `:celluloid`:
52
+
53
+ ```ruby
54
+ redis = Redis.new(:driver => :celluloid)
55
+ ```
56
+
57
+ ## Contributing
58
+
59
+ * Fork this repository on github
60
+ * Make your changes and send us a pull request
61
+ * If we like them we'll merge them
62
+ * If we've accepted a patch, feel free to ask for commit access
63
+
64
+ ## License
65
+
66
+ Copyright (c) 2013 Tony Arcieri. Distributed under the MIT License. See
67
+ LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ Dir["tasks/**/*.rake"].each { |task| load task }
3
+
4
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'celluloid/redis/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "celluloid-redis"
8
+ spec.version = Celluloid::Redis::VERSION
9
+ spec.authors = ["Tony Arcieri"]
10
+ spec.email = ["tony.arcieri@gmail.com"]
11
+ spec.description = "Celluloid::IO support for the redis-rb library"
12
+ spec.summary = "celluloid-redis provides a redis-rb connection class using Celluloid::IO"
13
+ spec.homepage = "https://github.com/celluloid/celluloid-redis"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "redis"
22
+ spec.add_runtime_dependency "celluloid-io", ">= 0.13.0.pre"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "guard-rspec"
28
+ end
@@ -0,0 +1,4 @@
1
+ require "redis"
2
+
3
+ require "celluloid/redis/version"
4
+ require "celluloid/redis/redis_ext"
@@ -0,0 +1,28 @@
1
+ class Redis
2
+ class Client
3
+ # Well this is really sad. redis-rb does not provide extensible driver
4
+ # support. Instead they couple everything together though this method.
5
+ # This leaves us no choice but to monkeypatch
6
+ def _parse_driver(driver)
7
+ driver = driver.to_s if driver.is_a?(Symbol)
8
+
9
+ if driver.kind_of?(String)
10
+ case driver
11
+ when "ruby"
12
+ require "redis/connection/ruby"
13
+ driver = Connection::Ruby
14
+ when "celluloid"
15
+ require "redis/connection/celluloid"
16
+ driver = Connection::Celluloid
17
+ when "hiredis"
18
+ require "redis/connection/hiredis"
19
+ driver = Connection::Hiredis
20
+ else
21
+ raise "Unknown driver: #{driver}"
22
+ end
23
+ end
24
+
25
+ driver
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module Celluloid
2
+ module Redis
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,102 @@
1
+ require "redis/connection/registry"
2
+ require "redis/connection/command_helper"
3
+ require "redis/errors"
4
+ require "celluloid/io"
5
+
6
+ class Redis
7
+ module Connection
8
+ class Celluloid
9
+ include Redis::Connection::CommandHelper
10
+
11
+ MINUS = "-".freeze
12
+ PLUS = "+".freeze
13
+ COLON = ":".freeze
14
+ DOLLAR = "$".freeze
15
+ ASTERISK = "*".freeze
16
+
17
+ def self.connect(config)
18
+ # TODO: config[:timeout] support
19
+ if config[:scheme] == "unix"
20
+ sock = ::Celluloid::IO::UNIXSocket.open(config[:path])
21
+ else
22
+ sock = ::Celluloid::IO::TCPSocket.open(config[:host], config[:port])
23
+ end
24
+
25
+ new(sock)
26
+ end
27
+
28
+ def initialize(sock)
29
+ @sock = sock
30
+ end
31
+
32
+ def connected?
33
+ !!@sock
34
+ end
35
+
36
+ def disconnect
37
+ @sock.close rescue nil
38
+ ensure
39
+ @sock = nil
40
+ end
41
+
42
+ def timeout=(timeout)
43
+ if @sock.respond_to?(:timeout=)
44
+ @sock.timeout = timeout
45
+ end
46
+ end
47
+
48
+ def write(command)
49
+ @sock.write(build_command(command))
50
+ end
51
+
52
+ def read
53
+ line = @sock.gets
54
+ reply_type = line.slice!(0, 1)
55
+ format_reply(reply_type, line)
56
+
57
+ rescue Errno::EAGAIN
58
+ raise TimeoutError
59
+ end
60
+
61
+ def format_reply(reply_type, line)
62
+ case reply_type
63
+ when MINUS then format_error_reply(line)
64
+ when PLUS then format_status_reply(line)
65
+ when COLON then format_integer_reply(line)
66
+ when DOLLAR then format_bulk_reply(line)
67
+ when ASTERISK then format_multi_bulk_reply(line)
68
+ else raise ProtocolError.new(reply_type)
69
+ end
70
+ end
71
+
72
+ def format_error_reply(line)
73
+ CommandError.new(line.strip)
74
+ end
75
+
76
+ def format_status_reply(line)
77
+ line.strip
78
+ end
79
+
80
+ def format_integer_reply(line)
81
+ line.to_i
82
+ end
83
+
84
+ def format_bulk_reply(line)
85
+ bulklen = line.to_i
86
+ return if bulklen == -1
87
+ reply = encode(@sock.read(bulklen))
88
+ @sock.read(2) # Discard CRLF.
89
+ reply
90
+ end
91
+
92
+ def format_multi_bulk_reply(line)
93
+ n = line.to_i
94
+ return if n == -1
95
+
96
+ Array.new(n) { read }
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ Redis::Connection.drivers << Redis::Connection::Celluloid
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ describe Redis::Connection::Celluloid do
4
+ let(:example_key) { 'foobar' }
5
+ let(:example_value) { 'baz' }
6
+
7
+ it "connects to Redis" do
8
+ redis = Redis.new(:driver => :celluloid)
9
+
10
+ # FIXME: perhaps some better tests are in order here?
11
+ redis.set(example_key, '')
12
+ redis.get(example_key).should eq ''
13
+
14
+ redis.set(example_key, example_value)
15
+ redis.get(example_key).should eq example_value
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ require "celluloid/redis"
2
+ require "redis/connection/celluloid"
3
+ require "coveralls"
4
+ Coveralls.wear!
data/tasks/rspec.rake ADDED
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new
4
+
5
+ RSpec::Core::RakeTask.new(:rcov) do |task|
6
+ task.rcov = true
7
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: celluloid-redis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tony Arcieri
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redis
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: celluloid-io
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.13.0.pre
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.13.0.pre
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Celluloid::IO support for the redis-rb library
111
+ email:
112
+ - tony.arcieri@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .coveralls.yml
118
+ - .gitignore
119
+ - .rspec
120
+ - .travis.yml
121
+ - CHANGES.md
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - celluloid-redis.gemspec
127
+ - lib/celluloid/redis.rb
128
+ - lib/celluloid/redis/redis_ext.rb
129
+ - lib/celluloid/redis/version.rb
130
+ - lib/redis/connection/celluloid.rb
131
+ - spec/redis/connection/celluloid_spec.rb
132
+ - spec/spec_helper.rb
133
+ - tasks/rspec.rake
134
+ homepage: https://github.com/celluloid/celluloid-redis
135
+ licenses:
136
+ - MIT
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ segments:
148
+ - 0
149
+ hash: 1868622521016118762
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ segments:
157
+ - 0
158
+ hash: 1868622521016118762
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 1.8.23
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: celluloid-redis provides a redis-rb connection class using Celluloid::IO
165
+ test_files:
166
+ - spec/redis/connection/celluloid_spec.rb
167
+ - spec/spec_helper.rb