user647527 user647527 - 1 year ago 93
Ruby Question

How to call redis.evalsha

I faced a doubt on how to use r.evalsha under ruby. I able to get result on CLI to call redis. Error shown me: attempt to concatenate local 'nid' (a boolean value)

Please advise me .

Thank You.

evalsha 0ca2da3beea9739f3d61798a36bd4d5ed56754ee 1

The testredis.rb like at following:

require 'rubygems'
require 'redis'
r = => '', :port => '6379' )
$result = r.evalsha("0ca2da3beea9739f3d61798a36bd4d5ed56754ee", ['1'], [''])
puts $result

Answer Source

The ruby redis gem attempts to clean up some things for you. You don't need to pass the number of arguments. The second argument to evalsha is an array of script arguments. Your evalsha line should look like this:

$result = r.evalsha("0ca2da3beea9739f3d61798a36bd4d5ed56754ee", [''])

To load a script from within ruby you can use Redis#script:

sha = r.script(:load, "return'incr', 'foo')")
r.evalsha(sha) # => 1
r.evalsha(sha) # => 2
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download