7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/infrataster/contexts/redis_context.rb', line 7
def result
options = {host: 'localhost', port: 6379, db: 15}
if server.options[:redis]
options = options.merge(server.options[:redis])
end
query, arguments = resource.query.split(' ', 2)
if query == "set" or query == "get"
arguments = arguments.scan(/'[^']*'/).map{|n| eval n}
end
if options.has_key?(:url)
resource.redis = Redis.new(:url => "#{options[:url]}")
elsif options.has_key?(:password)
resource.redis = Redis.new(:host=>"#{options[:host]}",
:port=>"#{options[:port]}",
:db=>"#{options[:db]}",
:password=> "#{options[:password]}")
else
resource.redis = Redis.new(:host=>"#{options[:host]}",
:port=>"#{options[:port]}",
:db=>"#{options[:db]}")
end
if resource.redis.respond_to?(query)
resource.redis.method(query).call(*arguments)
end
end
|