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.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <kamailio/kamailio/issues/3526@github.com>