redis-roc 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/redis-roc.rb +2 -0
- data/lib/roc/ext/redis_ext.rb +20 -0
- data/lib/roc/objects/base.rb +81 -0
- data/lib/roc/objects/float.rb +32 -0
- data/lib/roc/objects/hash.rb +134 -0
- data/lib/roc/objects/integer.rb +51 -0
- data/lib/roc/objects/list.rb +204 -0
- data/lib/roc/objects/lock.rb +53 -0
- data/lib/roc/objects/set.rb +148 -0
- data/lib/roc/objects/sorted_set.rb +217 -0
- data/lib/roc/objects/string.rb +116 -0
- data/lib/roc/objects/time.rb +62 -0
- data/lib/roc/objects.rb +11 -0
- data/lib/roc/store/object_initializers.rb +74 -0
- data/lib/roc/store/redis_eval.rb +7 -0
- data/lib/roc/store/redis_store.rb +76 -0
- data/lib/roc/store/roc_store.rb +11 -0
- data/lib/roc/store/transient_eval.rb +42 -0
- data/lib/roc/store/transient_store.rb +1425 -0
- data/lib/roc/store.rb +2 -0
- data/lib/roc/types/all_types.rb +41 -0
- data/lib/roc/types/array_type.rb +106 -0
- data/lib/roc/types/method_generators.rb +38 -0
- data/lib/roc/types/scalar_type.rb +58 -0
- data/lib/roc/types/sortable_type.rb +32 -0
- data/lib/roc/version.rb +3 -0
- metadata +114 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rufus/lua'
|
2
|
+
module ROC
|
3
|
+
module Store
|
4
|
+
module TransientEval
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def eval(script, num_key_args, *args)
|
9
|
+
s = Rufus::Lua::State.new
|
10
|
+
|
11
|
+
s['KEYS'] = args.slice(0...num_key_args)
|
12
|
+
s['ARGV'] = args.slice(num_key_args...args.size)
|
13
|
+
s['redis'] = {}
|
14
|
+
|
15
|
+
s.function('redis.call') do |*args|
|
16
|
+
command = args.shift.to_sym
|
17
|
+
self.call command, *args
|
18
|
+
end
|
19
|
+
s.function('redis.log') do |*args|
|
20
|
+
puts args.map{|x| rec_to_r(x)}.join(' ')
|
21
|
+
end
|
22
|
+
|
23
|
+
res = s.eval(script)
|
24
|
+
rec_to_r(res)
|
25
|
+
end
|
26
|
+
|
27
|
+
def rec_to_r(obj)
|
28
|
+
if obj.is_a?(Rufus::Lua::Table)
|
29
|
+
robj = obj.to_ruby
|
30
|
+
if robj.is_a?(Array)
|
31
|
+
robj.map{|x| rec_to_r(x)}
|
32
|
+
elsif robj.is_a?(Hash)
|
33
|
+
Hash[robj.map{|pair| [pair[0], rec_to_r(pair[1])]}]
|
34
|
+
end
|
35
|
+
else
|
36
|
+
obj
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|