Running `5.7.1:441300`, trying to loop through the results of an `HGETALL` operation in Redis:
``` 127.0.0.1:6379[1]> keys * 1) "customer_params:14045551212:1.1.1.1" 127.0.0.1:6379[1]> hgetall customer_params:14045551212:1.1.1.1 1) "auth_ha1" 2) "9febe8cf72c6bd063b8978cded892e4bb" ```
This means that the returned type will be `$redisd(rpl_arr)` and a loop is required. For any given key value `$redis(r=>value[x])`, the value is in the next array slot, at `$redis(r=>value[x + 1])`.
With that in mind, I tried this loop:
``` $var(i) = 0;
while($var(i) < $redis(r=>size)) { $var(key) = $redis(r=>value[$var(i)]);
switch($var(key)) { case "auth_ha1": $var(auth_ha1) = $redis(r=>value[$var(i)+1]); break; }
$var(i) = $var(i) + 1; } ```
However, this ends up storing the key value ("auth_ha1") in `$var(auth_ha1)`. I also tried `$(var(i){s.int}) + 1` for the subscript value.
To get the actual next-slot value, the expression evaluation has to be externalised into an intermediate variable:
``` while($var(i) < $redis(r=>size)) { $var(key) = $redis(r=>value[$var(i)]);
# For some reason, Kamailio cannot evaluate an addition expression inside this subscript: $redis(r=>value[EXPR]) $var(idx) = $var(i) + 1;
switch($var(key)) { case "auth_ha1": $var(auth_ha1) = $redis(r=>value[$var(idx)]); break; }
$var(i) = $var(i) + 1; } ```
This works, and yields `9febe8cf72c6bd063b8978cded892e4bb`.
This is not a bug, but how it is designed/supported by the index part, which can be a number or a variable, not an expression. Same is for index of avp, xavp or headers, just to give a few examples.
If someone wants to extend, can make a pull request. So, if nobody wants to take over it soon, this issue will be closed. The PR can be done independently.
Oh, okay! Did not know. Sorry.—Sent from mobile, apologies for brevity and errors.On Jul 27, 2023, at 2:30 AM, Daniel-Constantin Mierla ***@***.***> wrote: This is not a bug, but how it is designed/supported by the index part, which can be a number or a variable, not an expression. Same is for index of avp, xavp or headers, just to give a few examples. If someone wants to extend, can make a pull request. So, if nobody wants to take over it soon, this issue will be closed. The PR can be done independently.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
This issue is stale because it has been open 6 weeks with no activity. Remove stale label or comment or this will be closed in 2 weeks.
Closed #3526 as completed.