redis-connection-universal 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/lib/redis/connection/universal.rb +26 -0
- data/redis-connection-universal.gemspec +16 -0
- metadata +64 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Michael Gorsuch
|
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,46 @@
|
|
1
|
+
# Redis::Connection::Universal
|
2
|
+
|
3
|
+
This is an experiment in creating a Redis connection that is
|
4
|
+
capable of using multiple transports to connect to multiple Redis
|
5
|
+
servers. It will determine the transport type based on the URL
|
6
|
+
schema.
|
7
|
+
|
8
|
+
The connection driver is currently capable of connecting to both
|
9
|
+
standard redis instances (redis://) as well as ssl secured ones
|
10
|
+
(redis+ssl://).
|
11
|
+
|
12
|
+
This gem currently relies on a forked version of the redis gem
|
13
|
+
(https://github.com/gorsuch/redis-rb/tree/expand-connection-context),
|
14
|
+
which currently has a pull request open against the upstream tree
|
15
|
+
(https://github.com/redis/redis-rb/pull/191).
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add these lines to your application's Gemfile:
|
20
|
+
|
21
|
+
gem "redis", :git => "git://github.com/gorsuch/redis-rb", :ref => "9c8ee97d8b6e8f1c7fc42df63d93e4476e34a462"
|
22
|
+
gem 'redis-connection-universal'
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Taking advantage of this driver is very simple - just require it.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'redis'
|
34
|
+
require 'redis-connection-universal'
|
35
|
+
|
36
|
+
r = Redis.new url: "redis+ssl://myhost:6380"
|
37
|
+
r.info
|
38
|
+
```
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
class Redis
|
5
|
+
module Connection
|
6
|
+
class Universal < Ruby
|
7
|
+
def connect(uri, timeout)
|
8
|
+
super if uri.scheme == 'redis'
|
9
|
+
return connect_ssl(uri, timeout) if uri.scheme == 'redis+ssl'
|
10
|
+
end
|
11
|
+
|
12
|
+
def connect_ssl(uri, timeout)
|
13
|
+
with_timeout(timeout.to_f / 1_000_000) do
|
14
|
+
tcp_sock = TCPSocket.new(uri.host, uri.port)
|
15
|
+
tcp_sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
|
16
|
+
ssl_context = OpenSSL::SSL::SSLContext.new()
|
17
|
+
@sock = OpenSSL::SSL::SSLSocket.new(tcp_sock, ssl_context)
|
18
|
+
@sock.sync_close = true
|
19
|
+
@sock.connect
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Redis::Connection.drivers << Redis::Connection::Universal
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.authors = ["Michael Gorsuch"]
|
4
|
+
gem.email = ["michael.gorsuch@gmail.com"]
|
5
|
+
gem.description = %q{universal redis driver to connect that allows for multiple transports}
|
6
|
+
gem.summary = gem.description
|
7
|
+
gem.homepage = "http://github.com/gorsuch/redis-connection-universal"
|
8
|
+
|
9
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
10
|
+
gem.files = `git ls-files`.split("\n")
|
11
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
12
|
+
gem.name = "redis-connection-universal"
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
gem.version = '0.0.1'
|
15
|
+
gem.add_dependency("redis")
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis-connection-universal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Gorsuch
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redis
|
16
|
+
requirement: &70363062133360 !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: *70363062133360
|
25
|
+
description: universal redis driver to connect that allows for multiple transports
|
26
|
+
email:
|
27
|
+
- michael.gorsuch@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/redis/connection/universal.rb
|
38
|
+
- redis-connection-universal.gemspec
|
39
|
+
homepage: http://github.com/gorsuch/redis-connection-universal
|
40
|
+
licenses: []
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.10
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: universal redis driver to connect that allows for multiple transports
|
63
|
+
test_files: []
|
64
|
+
has_rdoc:
|