redis-scripted 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/README.md +34 -0
- data/redis-scripted.gemspec +19 -0
- data/test/redis.conf +3 -0
- data/test/rediscripted.rb +39 -0
- metadata +70 -0
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
`Redis::Scripted`
|
2
|
+
===
|
3
|
+
|
4
|
+
A Ruby client that supports the experimental scripting feature in Redis.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
---
|
8
|
+
|
9
|
+
Drop your Lua scripts in `./scripts`:
|
10
|
+
|
11
|
+
scripts/
|
12
|
+
├── msadd.lua
|
13
|
+
└── sintercard.lua
|
14
|
+
|
15
|
+
Then initialize the connection to Redis, passing the path where the
|
16
|
+
class should look for scripts:
|
17
|
+
|
18
|
+
require "redis/scripted"
|
19
|
+
|
20
|
+
redis = Redis.connect(scripts_path: "./scripts")
|
21
|
+
|
22
|
+
The scripts are defined as instance methods for convenience:
|
23
|
+
|
24
|
+
redis.msadd(["foo"], ["s1", "s2", "s3"])
|
25
|
+
|
26
|
+
Note that `msadd` receives two arguments at most: one array for the keys
|
27
|
+
and another for the values. This is necessary because of [how `EVAL`
|
28
|
+
works](http://antirez.com/post/scripting-branch-released.html).
|
29
|
+
|
30
|
+
Acknowledgments
|
31
|
+
===
|
32
|
+
|
33
|
+
Code was inspired by [mkrecny](https://github.com/mkrecny/redis-extend)
|
34
|
+
and [catwell](https://github.com/catwell/redis-extend).
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "redis-scripted"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.summary = "A Ruby client that supports the experimental scripting feature of Redis"
|
5
|
+
s.authors = ["Damian Janowski"]
|
6
|
+
s.email = ["djanowski@dimaion.com"]
|
7
|
+
s.homepage = "http://github.com/djanowski/redis-scripted"
|
8
|
+
|
9
|
+
s.add_dependency("redis")
|
10
|
+
|
11
|
+
s.files = Dir[
|
12
|
+
"LICENSE",
|
13
|
+
"README*",
|
14
|
+
"Rakefile",
|
15
|
+
"bin/*",
|
16
|
+
"*.gemspec",
|
17
|
+
"test/*.*"
|
18
|
+
]
|
19
|
+
end
|
data/test/redis.conf
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "cutest"
|
2
|
+
|
3
|
+
def root(path)
|
4
|
+
File.expand_path("../#{path}", File.dirname(__FILE__))
|
5
|
+
end
|
6
|
+
|
7
|
+
require root("lib/redis/scripted")
|
8
|
+
|
9
|
+
redis = Redis::Scripted.new(port: 6399, scripts_path: root("test/scripts"))
|
10
|
+
|
11
|
+
prepare do
|
12
|
+
Process.kill(:INT, File.read("test/redis.pid").to_i) if File.exist?("test/redis.pid")
|
13
|
+
`redis-server test/redis.conf`
|
14
|
+
sleep 0.1
|
15
|
+
end
|
16
|
+
|
17
|
+
test "runs Lua code" do
|
18
|
+
redis.sadd("foo", "s1")
|
19
|
+
redis.sadd("foo", "s2")
|
20
|
+
redis.sadd("bar", "s1")
|
21
|
+
|
22
|
+
assert_equal redis.sintercard(["foo", "bar"]), 1
|
23
|
+
end
|
24
|
+
|
25
|
+
test "sends keys and values" do
|
26
|
+
redis.msadd(["foo"], %w(s1 s2 s3))
|
27
|
+
|
28
|
+
assert_equal %w(s1 s2 s3), redis.smembers("foo").sort
|
29
|
+
end
|
30
|
+
|
31
|
+
test "uses EVALSHA" do
|
32
|
+
redis.sadd("foo", "s1")
|
33
|
+
redis.sadd("foo", "s2")
|
34
|
+
redis.sadd("bar", "s1")
|
35
|
+
|
36
|
+
redis.sintercard(["foo", "bar"])
|
37
|
+
|
38
|
+
assert_equal Redis.new(port: 6399).client.call(:evalsha, "d76ce5687840f0436ae4c09c50564cf0e537395e", 2, "foo", "bar"), 1
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis-scripted
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Damian Janowski
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-07 00:00:00 -03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: redis
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- djanowski@dimaion.com
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files: []
|
35
|
+
|
36
|
+
files:
|
37
|
+
- README.md
|
38
|
+
- redis-scripted.gemspec
|
39
|
+
- test/redis.conf
|
40
|
+
- test/rediscripted.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/djanowski/redis-scripted
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.6.2
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: A Ruby client that supports the experimental scripting feature of Redis
|
69
|
+
test_files: []
|
70
|
+
|