[OpenSIPS-Users] Redis EVAL calls

Donat Zenichev donat.zenichev at gmail.com
Sun Mar 15 13:19:41 EST 2020


Might be, the following information can be useful.
I found out, that OpenSIPS sends eval command separated by a space sign.

So basically if I was to send this:   eval "return
{KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second
OpenSIPS sends it in parts like:
eval
"return
{KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"
2
key1
key2
first
second

And seems, that Redis considers a script body then as two separate
arguments:
the first: "return
then second: {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"


On Sat, Mar 14, 2020 at 3:42 PM Donat Zenichev <donat.zenichev at gmail.com>
wrote:

> Hi there!
>
> I have a question regarding how to better work with redis eval
> functionality.
> For the current moment I'm trying to implement this using usual
> cache_raw_query() function.
>
> Here is an example of the simple eval call, that basically checks if a
> value is a member of the set:
> $var(script_body) = "\"local str = ARGV[1]; for i=1,str:len(),1 do if (1
> == redis.call('sismember', 'certain_keys_set', str:sub(1,i))) then return
> 1; end; end; return 0;\"";
>
> Then I call it with:
> cache_raw_query("redis:opensips", "EVAL $var(script_body) 0 $rU",
> "$avp(result)");
>
> The obstacle I've come across is that for some reason, cachedb_redis
> module throws the following error:
> "ERROR:cachedb_redis:redis_raw_query_send: Redis operation failure - ERR
> value is not an integer or out of range"
>
> This script works out well though, when I insert this directly into
> redis-cli.
>
> I have an idea, that this can be caused by zero "0" following the script
> body.
> I tried to convert zero into integer with {s.int} but this gave no result.
>
> I also tried to escape the whole body script with {s.escape.common} but
> this also didn't work out.
> On the other hand, I tried to escape all semicolons, colons, single and
> double quotations with a usual escape symbol "\", and this also doesn't
> give any good result.
>
> From what I understand, this is kind of an issue related to formatting of
> string I'm trying to send to the Redis server.
> And if I understand this correctly, OpenSIPS does nothing else, but pass
> the input string to the redisvCommand() API function. So I'm pretty
> confident this has to do something with formatting.
>
> Might be there is some known method, I need use in order to properly
> encode my string (script body) before being able to send it to Redis?
> For e.g. using using base64 or somewhat like that.
>
> In any way, I appreciate all ideas on the matter!
>
> --
>
> Best regards,
> Donat Zenichev
>
>

-- 

Best regards,
Donat Zenichev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20200315/9c8d5eab/attachment-0001.html>


More information about the Users mailing list