redic 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +19 -0
- data/README.md +38 -0
- data/lib/redic.rb +33 -0
- data/redic.gemspec +14 -0
- data/test/redic_test.rb +26 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22a26d943e92d11d2dbe989f1b7439453376b2e5
|
4
|
+
data.tar.gz: c9f7001a56b5a853282339e5dd3976dceb7bedd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d515e2ae172a21083ec61445828dac0c4edc5bea6599c8f525cfa9a6e97ff6c3e5e597b98232f7852c08cd79c5dc2b8e4318b8c96253617535bed108d045ce9
|
7
|
+
data.tar.gz: 95d6eed5fb6210f0147ae46fb4f4940c218dfef27242f12e1ea628d3a19298e023ac6b9db4110b7ca8e7ae40f9763d31fe5187ff52c846d86413968da59d0e47
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Michel Martens, Cyril David
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
Redic
|
2
|
+
=====
|
3
|
+
|
4
|
+
Lightweight Redis Client
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Wrapper for `Redis::Client` that avoids rubyisms. It is inspired
|
10
|
+
by [redigo](https://github.com/garyburd/redigo), a Redis client
|
11
|
+
library for golang.
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
# Accepts the same options as Redis.new
|
17
|
+
redis = Redic.new
|
18
|
+
|
19
|
+
# Processes the command and returns the response.
|
20
|
+
c.call("SET", "foo", "bar")
|
21
|
+
|
22
|
+
assert_equal "bar", c.call("GET", "foo")
|
23
|
+
|
24
|
+
# Pipelining is implemented by buffering commands,
|
25
|
+
# then calling Redic#run
|
26
|
+
c.write("SET", "foo", "bar")
|
27
|
+
c.write("GET", "foo")
|
28
|
+
|
29
|
+
assert_equal ["OK", "bar"], c.run
|
30
|
+
```
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
You can install it using rubygems.
|
35
|
+
|
36
|
+
```
|
37
|
+
$ gem install redic
|
38
|
+
```
|
data/lib/redic.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "redis"
|
2
|
+
|
3
|
+
class Redic
|
4
|
+
def initialize(options = {})
|
5
|
+
@client = Redis::Client.new(options)
|
6
|
+
@buffer = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(*args)
|
10
|
+
@client.send(:ensure_connected) do
|
11
|
+
@client.write(args)
|
12
|
+
@client.read
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def write(*args)
|
17
|
+
@buffer << args
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
@client.send(:ensure_connected) do
|
22
|
+
@buffer.each do |args|
|
23
|
+
@client.write(args)
|
24
|
+
end
|
25
|
+
|
26
|
+
@buffer.map do
|
27
|
+
@client.read
|
28
|
+
end
|
29
|
+
end
|
30
|
+
ensure
|
31
|
+
@buffer.clear
|
32
|
+
end
|
33
|
+
end
|
data/redic.gemspec
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "redic"
|
5
|
+
s.version = "0.0.2"
|
6
|
+
s.summary = "Lightweight Redis Client"
|
7
|
+
s.description = "Wrapper for Redis::Client that avoids rubyisms."
|
8
|
+
s.authors = ["Michel Martens", "Cyril David"]
|
9
|
+
s.email = ["michel@soveran.com", "me@cyrildavid.com"]
|
10
|
+
s.homepage = "https://github.com/amakawa/redic"
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.license = "MIT"
|
13
|
+
s.add_dependency "redis"
|
14
|
+
end
|
data/test/redic_test.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path("../lib/redic", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
setup do
|
4
|
+
Redic.new
|
5
|
+
end
|
6
|
+
|
7
|
+
test "normal commands" do |c|
|
8
|
+
c.call("SET", "foo", "bar")
|
9
|
+
|
10
|
+
assert_equal "bar", c.call("GET", "foo")
|
11
|
+
end
|
12
|
+
|
13
|
+
test "pipelining" do |c|
|
14
|
+
c.write("SET", "foo", "bar")
|
15
|
+
c.write("GET", "foo")
|
16
|
+
|
17
|
+
assert_equal ["OK", "bar"], c.run
|
18
|
+
end
|
19
|
+
|
20
|
+
test "multi/exec" do |c|
|
21
|
+
c.write("MULTI")
|
22
|
+
c.write("SET", "foo", "bar")
|
23
|
+
c.write("EXEC")
|
24
|
+
|
25
|
+
assert_equal ["OK", "QUEUED", ["OK"]], c.run
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
@@ -32,7 +32,12 @@ email:
|
|
32
32
|
executables: []
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
|
-
files:
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- lib/redic.rb
|
39
|
+
- redic.gemspec
|
40
|
+
- test/redic_test.rb
|
36
41
|
homepage: https://github.com/amakawa/redic
|
37
42
|
licenses:
|
38
43
|
- MIT
|