Module: kamailio
Branch: master
Commit: 0bf901966aac3026cd0ba4798f5689c66d7f7b4f
URL: https://github.com/kamailio/kamailio/commit/0bf901966aac3026cd0ba4798f5689c…
Author: Kamailio Dev <kamailio.dev(a)kamailio.org>
Committer: Kamailio Dev <kamailio.dev(a)kamailio.org>
Date: 2017-06-02T15:31:37+02:00
modules: readme files regenerated - ndb_redis ... [skip ci]
---
Modified: src/modules/ndb_redis/README
---
Diff: https://github.com/kamailio/kamailio/commit/0bf901966aac3026cd0ba4798f5689c…
Patch: https://github.com/kamailio/kamailio/commit/0bf901966aac3026cd0ba4798f5689c…
---
diff --git a/src/modules/ndb_redis/README b/src/modules/ndb_redis/README
index 8ef7d7dd9c..c51fe48c3b 100644
--- a/src/modules/ndb_redis/README
+++ b/src/modules/ndb_redis/README
@@ -314,6 +314,12 @@ modparam("ndb_redis", "flush_on_reconnect", 1)
* value[n] - returns value of the nth element. value - returns null
for an array. You need to get each element by index.
+ In case one of the members of the array is also an array (for example
+ calling SMEMBERS in a MULTI/EXEC transaction), the members of the array
+ can be accessed by adding any of the above keys, after a value[n] key.
+ The first value[n] references the element in the first array, while the
+ next key references an element of the referenced array.
+
Example 1.9. redis_cmd usage
...
if(redis_cmd("srvN", "INCR cnt", "r")) {
@@ -344,6 +350,16 @@ if(redis_cmd("srvN", "HMGET foo_key field1 field3", "r")) {
xlog("array size: $redis(r=>size)\n");
xlog("first values: $redis(r=>value[0]) , $redis(r=>value[1])\n");
}
+
+
+# array as element of an array example
+redis_cmd("srvN", "MULTI", "r1");
+redis_cmd("srvN", "SMEMBERS foo", "r2");
+if (redis_cmd("srvN", "EXEC", "r")) {
+ xlog("array size: $redis(r=>value[0]=>size)\n");
+ xlog("first member of the set:$redis(r=>value[0]=>value[0])\n");
+ xlog("type of the second member of the set:$redis(r=>value[0]=>type[1])\n");
+}
...
4.2. redis_pipe_cmd(srvname, command, ..., replyid)
Hello,
I have enhanced the way REDIS replied are accessed in the Kamailio config, to be able to access arrays that are members of other arrays. In the original code, we could access members of an array like this: $redis(reply=>value[0]).
But if that member was itself an array it was impossible to access it, as accessing an array directly returns (null). This case can happen if we use redis transactions with, and all commands are given between MULTI and EXEC commands. Then the EXEC command returns an array with the responses of the individual commands, so if any command returns an array, then we have an array within that array.
I have modified the syntax of the redis replies in the config, to be able to add other keys after value[n] keys. This way we can access members of the array within the first array.
For example after the following sequence:
```
redis_cmd("srvN", "MULTI", "r1");
redis_cmd("srvN", "SMEMBERS foo", "r2");
redis_cmd("srvN", "EXEC", "reply")
```
The PV to access the response will look like this
- to access the first elemenent of SMEMBERS:
`$redis(reply=>value[0]=>value[0])`
- to access the second element of SMEMBERS:
`$redis(reply=>value[0]=>value[1])`
- to see how many elements SMEMBERS returned:
`$redis(reply=>value[0]=>size)`
- to see the type the first element returned by SMEMBERS:
`$redis(reply=>value[0]=>type[0])`
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/1147
-- Commit Summary --
* ndb_redis: enhance access to REDIS replies
-- File Changes --
M src/modules/ndb_redis/doc/ndb_redis_admin.xml (16)
M src/modules/ndb_redis/ndb_redis_mod.c (181)
M src/modules/ndb_redis/redis_client.h (4)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/1147.patchhttps://github.com/kamailio/kamailio/pull/1147.diff
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/1147