<div dir="ltr"><div>Might be, the following information can be useful.</div><div>I found out, that OpenSIPS sends eval command separated by a space sign.</div><div><br></div><div>So basically if I was to send this: eval "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second</div><div>OpenSIPS sends it in parts like:</div><div>eval</div><div>"return</div><div>{KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"</div><div>2</div><div>key1</div><div>key2</div><div>first</div><div>second</div><div><br></div><div>And seems, that Redis considers a script body then as two separate arguments:</div><div>the first: "return</div><div>then second: {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 14, 2020 at 3:42 PM Donat Zenichev <<a href="mailto:donat.zenichev@gmail.com">donat.zenichev@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi there!</div><div><br></div><div>I have a question regarding how to better work with redis eval functionality.</div><div></div><div>For the current moment I'm trying to implement this using usual cache_raw_query() function.<br></div><div><br></div><div>Here is an example of the simple eval call, that basically checks if a value is a member of the set:<br>$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;\"";</div><div><br></div><div>Then I call it with:<br></div><div>cache_raw_query("redis:opensips", "EVAL $var(script_body) 0 $rU", "$avp(result)");</div><div><br></div><div>The obstacle I've come across is that for some reason, cachedb_redis module throws the following error:<br>"ERROR:cachedb_redis:redis_raw_query_send: Redis operation failure - ERR value is not an integer or out of range"</div><div><br></div><div>This script works out well though, when I insert this directly into redis-cli.<br></div><div><br></div><div>I have an idea, that this can be caused by zero "0" following the script body.</div><div>I tried to convert zero into integer with {<a href="http://s.int" target="_blank">s.int</a>} but this gave no result.</div><div><br></div><div>I also tried to escape the whole body script with {s.escape.common} but this also didn't work out.</div><div>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.<br></div><div><br></div><div>From what I understand, this is kind of an issue related to formatting of string I'm trying to send to the Redis server.</div><div>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.<br></div><div><br></div><div>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?</div><div>For e.g. using using base64 or somewhat like that.<br></div><div><br></div><div>In any way, I appreciate all ideas on the matter!<br> </div><div><br>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><br></div><div dir="ltr"><div dir="ltr"><font style="background-color:rgb(255,255,255)" color="#0b5394">Best regards,<br></font></div><div dir="ltr"><font style="background-color:rgb(255,255,255)" color="#0b5394">Donat Zenichev<br><br></font></div></div></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><br></div><div dir="ltr"><div dir="ltr"><font style="background-color:rgb(255,255,255)" color="#0b5394">Best regards,<br></font></div><div dir="ltr"><font style="background-color:rgb(255,255,255)" color="#0b5394">Donat Zenichev<br><br></font></div></div></div></div></div></div></div></div>