jedis_rb 2.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +71 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/jedis_rb.gemspec +33 -0
- data/lib/jedis_rb/pool.rb +100 -0
- data/lib/jedis_rb/vendor.rb +3 -0
- data/lib/jedis_rb/version.rb +3 -0
- data/lib/jedis_rb/wrapped.rb +8 -0
- data/lib/jedis_rb.rb +4 -0
- data/lib/org/apache/commons/commons-pool2/2.3/commons-pool2-2.3.jar +0 -0
- data/lib/redis/clients/jedis/2.7.2/jedis-2.7.2.jar +0 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 69545127e8362dada7aa7679c304dbbeeb289b37
|
4
|
+
data.tar.gz: 283f1f02ed4bc018a819ca2a925089c85dcfaea1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c72ffd46f63d5653b9a43d8a6efc5aa70d902c740061d17c59318540736931f32ad9ad75b74c3e25ccfe048dc720aa7e0a353258d2e098786f348c14101f8d6f
|
7
|
+
data.tar.gz: 4214a8bf95ea6c967544cb553e086e8ff237b9e1772aa9303c60598e13316ebb11592c05a21a35eef5471163290f86996bba43f02219de8fcb56dc65dd86b661
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 ASMALLWORLD
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# JedisRb
|
2
|
+
|
3
|
+
A JRuby wrapper around the Jedis client library for Redis. Requires JRuby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'jedis_rb'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install jedis_rb
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```
|
24
|
+
RedisPool = JedisRb::Pool.new
|
25
|
+
=> #<JedisRb::Pool:0x19fe4644 @pool=#<Java::RedisClientsJedis::JedisPool:0x21d8bcbe>>
|
26
|
+
```
|
27
|
+
|
28
|
+
```
|
29
|
+
RedisPool.execute(:ping)
|
30
|
+
=> "PONG"
|
31
|
+
```
|
32
|
+
|
33
|
+
```
|
34
|
+
RedisPool.execute :get, 'foo'
|
35
|
+
=> nil
|
36
|
+
```
|
37
|
+
|
38
|
+
```
|
39
|
+
RedisPool.execute :set, 'foo', 'fish'
|
40
|
+
=> "OK"
|
41
|
+
```
|
42
|
+
|
43
|
+
```
|
44
|
+
RedisPool.execute :get, 'foo'
|
45
|
+
=> "fish"
|
46
|
+
```
|
47
|
+
|
48
|
+
```
|
49
|
+
RedisPool.execute :setex, 'foo', 600, 'fish'
|
50
|
+
=> "OK"
|
51
|
+
```
|
52
|
+
|
53
|
+
Or in parallel, in a block:
|
54
|
+
|
55
|
+
```
|
56
|
+
RedisPool.with_connection do |c|
|
57
|
+
c.set ..., ...
|
58
|
+
c.sadd ..., ...
|
59
|
+
c.get ...
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/asmallworldsite/jedis_rb.
|
66
|
+
|
67
|
+
|
68
|
+
## License
|
69
|
+
|
70
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
71
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jedis_rb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/jedis_rb.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jedis_rb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jedis_rb"
|
8
|
+
spec.version = JedisRb::VERSION
|
9
|
+
spec.authors = ["Michael Sell"]
|
10
|
+
spec.email = ['michael@asw.com']
|
11
|
+
|
12
|
+
spec.summary = "A Ruby gem which wraps the Jedis Redis Java client, for use with JRuby"
|
13
|
+
spec.description = "A Ruby gem which wraps the Jedis Redis Java client, for use with JRuby"
|
14
|
+
spec.homepage = "https://github.com/asmallworldsite/jedis_rb"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module JedisRb
|
2
|
+
# Pool wraps redis.clients.jedis.JedisPool, providing a thread-safe pool
|
3
|
+
# of redis.clients.jedis.Jedis connections.
|
4
|
+
#
|
5
|
+
# It provides two methods for performing Redis operations:
|
6
|
+
# * #yield_connection - yields a Jedis instance to a block
|
7
|
+
# * #execute - executes a single Redis operation
|
8
|
+
#
|
9
|
+
class Pool
|
10
|
+
attr_reader :connection_pool
|
11
|
+
|
12
|
+
# Construct a new JedisRb Pool.
|
13
|
+
#
|
14
|
+
# Possible options are:
|
15
|
+
# * config - (redis.clients.jedis.JedisPoolConfig/Wrapped::PoolConfig) the pool configuration
|
16
|
+
# * host - (String) Redis host
|
17
|
+
# * port - (Integer) Redis port
|
18
|
+
# * connection_timeout - (Integer) the connection timeout in milliseconds
|
19
|
+
# * password - (String) Redis password
|
20
|
+
# * database - (Integer) Redis database
|
21
|
+
# * client_name (String) the client name
|
22
|
+
# * convert_objects (Boolean) Ruby object casting
|
23
|
+
#
|
24
|
+
# By passing in convert_objects: true, Pool can convert return values to
|
25
|
+
# their Ruby type equivalent. Currently, the following are supported:
|
26
|
+
# * java.util.Set => Set
|
27
|
+
# * java.util.Map => Hash
|
28
|
+
# * java.util.List => Array
|
29
|
+
#
|
30
|
+
# Depending on your use case, this conversion may be costly, so it is not
|
31
|
+
# the default. Please evaluate your application's requirements carefully
|
32
|
+
# before opting in.
|
33
|
+
def initialize(options={})
|
34
|
+
config = options.fetch(:config) { Wrapped::PoolConfig.new }
|
35
|
+
host = options.fetch(:host, Wrapped::Protocol::DEFAULT_HOST)
|
36
|
+
port = options.fetch(:post, Wrapped::Protocol::DEFAULT_PORT)
|
37
|
+
connection_timeout = options.fetch(:connection_timeout, Wrapped::Protocol::DEFAULT_TIMEOUT)
|
38
|
+
password = options.fetch(:password, nil)
|
39
|
+
database = options.fetch(:database, Wrapped::Protocol::DEFAULT_DATABASE)
|
40
|
+
client_name = options.fetch(:client_name, nil)
|
41
|
+
|
42
|
+
@convert_objects = options.fetch(:convert_objects, false)
|
43
|
+
|
44
|
+
@connection_pool = Wrapped::Pool.new(
|
45
|
+
config,
|
46
|
+
host,
|
47
|
+
port,
|
48
|
+
connection_timeout,
|
49
|
+
password,
|
50
|
+
database,
|
51
|
+
client_name
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Lease a connection from the pool and yield it to the given block.
|
56
|
+
#
|
57
|
+
# Leased connections will be automatically returned to the pool upon successful
|
58
|
+
# or unsuccessful execution of the block.
|
59
|
+
#
|
60
|
+
# Connections are of type redis.clients.jedis.Jedis.
|
61
|
+
# See the documentation[https://github.com/xetorthio/jedis/wiki] for more details.
|
62
|
+
def yield_connection
|
63
|
+
response = begin
|
64
|
+
resource = @connection_pool.resource
|
65
|
+
yield resource
|
66
|
+
ensure
|
67
|
+
resource.close if resource
|
68
|
+
end
|
69
|
+
|
70
|
+
if @convert_objects
|
71
|
+
convert(response)
|
72
|
+
else
|
73
|
+
response
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Execute a single action on the a Redis connection from the pool.
|
78
|
+
# Takes a method name and a splat of arguments to pass to the method.
|
79
|
+
#
|
80
|
+
# #execute uses #yield_connection to handle pool interaction.
|
81
|
+
def execute(method, *args)
|
82
|
+
yield_connection do |connection|
|
83
|
+
connection.send(method, *args)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
# Convert Java return values to their ruby equivalents.
|
90
|
+
def convert(value)
|
91
|
+
case value
|
92
|
+
when java.util.List then value.to_a
|
93
|
+
when java.util.Set then value.to_set
|
94
|
+
when java.util.Map then value.to_hash
|
95
|
+
else value
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
data/lib/jedis_rb.rb
ADDED
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jedis_rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.7.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Sell
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A Ruby gem which wraps the Jedis Redis Java client, for use with JRuby
|
56
|
+
email:
|
57
|
+
- michael@asw.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- jedis_rb.gemspec
|
72
|
+
- lib/jedis_rb.rb
|
73
|
+
- lib/jedis_rb/pool.rb
|
74
|
+
- lib/jedis_rb/vendor.rb
|
75
|
+
- lib/jedis_rb/version.rb
|
76
|
+
- lib/jedis_rb/wrapped.rb
|
77
|
+
- lib/org/apache/commons/commons-pool2/2.3/commons-pool2-2.3.jar
|
78
|
+
- lib/redis/clients/jedis/2.7.2/jedis-2.7.2.jar
|
79
|
+
homepage: https://github.com/asmallworldsite/jedis_rb
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata:
|
83
|
+
allowed_push_host: 'TODO: Set to ''http://mygemserver.com'''
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.0.14
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: A Ruby gem which wraps the Jedis Redis Java client, for use with JRuby
|
104
|
+
test_files: []
|