3 Daniel-Constantin Mierla
9 Daniel-Constantin Mierla
15 <vhernando@systemonenoc.com>
23 <carsten@ng-voice.com>
25 Copyright © 2011 asipto.com
27 Copyright © 2012 www.systemonenoc.com
29 Copyright © 2017 ng-voice GmbH
30 __________________________________________________________________
40 2.2. External Libraries or Applications
45 3.2. init_without_redis (integer)
46 3.3. connect_timeout (int)
47 3.4. cmd_timeout (int)
48 3.5. cluster (integer)
52 4.1. redis_cmd(srvname, command, ..., replyid)
53 4.2. redis_free(replyid)
57 1.1. Set server parameter
58 1.2. Set init_without_redis parameter
59 1.3. Set connect_timeout parameter
60 1.4. Set cmd_timeout parameter
61 1.5. Set cluster parameter
65 Chapter 1. Admin Guide
73 2.2. External Libraries or Applications
78 3.2. init_without_redis (integer)
79 3.3. connect_timeout (int)
80 3.4. cmd_timeout (int)
81 3.5. cluster (integer)
85 4.1. redis_cmd(srvname, command, ..., replyid)
86 4.2. redis_free(replyid)
90 This module provides a connector to interact with REDIS NoSQL Database
91 from configuration file. You can read more about REDIS at
94 It can connect to many REDIS servers and store the results in different
100 2.2. External Libraries or Applications
102 2.1. Kamailio Modules
104 The following modules must be loaded before this module:
107 2.2. External Libraries or Applications
109 The following libraries or applications must be installed before
110 running Kamailio with this module loaded:
111 * hiredis - available at https://github.com/antirez/hiredis .
116 3.2. init_without_redis (integer)
117 3.3. connect_timeout (int)
118 3.4. cmd_timeout (int)
119 3.5. cluster (integer)
123 Specify the details to connect to REDIS server. It takes a list of
124 attribute=value separated by semicolon, the attributes can be name,
125 unix, addr, port, db and pass. Name is a generic identifier to be used
126 with module functions. unix is the path to the unix domain socket
127 provided by redis server. addr and port are the IP address and the port
128 to connect to REDIS server. pass is the server password. unix and
129 (addr, port) are mutually exclusive. If both appear in same server
130 settings unix domain socket is configured. db is the DB number to use
131 (defaults to 0 if not specified).
133 You can set this parameter many times, in case you want to connect to
134 many REDIS servers, just give different attributes and use the specific
135 server name when querying the REDIS instance.
137 Default value is NULL.
139 Example 1.1. Set server parameter
141 modparam("ndb_redis", "server", "name=srvN;addr=127.0.0.1;port=6379;db=1")
142 modparam("ndb_redis", "server", "name=srvX;addr=127.0.0.2;port=6379;db=4;pass=my
146 modparam("ndb_redis", "server", "name=srvY;unix=/tmp/redis.sock;db=3")
149 3.2. init_without_redis (integer)
151 If set to 1, the module will correctly initialize even if redis is not
152 available at start up.
154 Default value is “0”.
156 Example 1.2. Set init_without_redis parameter
158 modparam("ndb_redis", "init_without_redis", 1)
161 3.3. connect_timeout (int)
163 The timeout when connecting to the redis server
165 Default value is 1000 ms.
167 Example 1.3. Set connect_timeout parameter
169 modparam("ndb_redis", "connect_timeout", 500)
172 3.4. cmd_timeout (int)
174 The timeout for each query to the redis server. If the redis server
175 does not reply within the timeout value, the command will fail and
176 kamailio will continue executing the cfg file.
178 Default value is 1000 ms.
180 Example 1.4. Set cmd_timeout parameter
182 modparam("ndb_redis", "cmd_timeout", 500)
185 3.5. cluster (integer)
187 If set to 1, the module will connect to servers indicated in the
190 Default value is “0” (disabled).
192 Example 1.5. Set cluster parameter
194 modparam("ndb_redis", "cluster", 1)
199 4.1. redis_cmd(srvname, command, ..., replyid)
200 4.2. redis_free(replyid)
202 4.1. redis_cmd(srvname, command, ..., replyid)
204 Send a command to REDIS server identified by srvname. The reply will be
205 stored in a local container identified by replyid. All the parameters
206 can be strings with pseudo-variables that are evaluated at runtime.
208 Minimum required arguments are srvname, command and replyid. Command
209 argument can be separated into several ones using %s token. (See
210 examples) Total number of arguments cannot exceed six.
212 The reply can be accessed via pseudo-variable $redis(key). The key can
213 be: type - type of the reply (as in hiredis.h); value - the value
214 returned by REDIS server; info - in case of error from REDIS, it will
215 contain an info message.
217 If reply type is an array (as in hiredis.h), there are other keys
219 * size - returns number of elements in the array.
220 * type[n] - returns the type of the nth element in the array. type -
222 * value[n] - returns value of the nth element. value - returns null
223 for an array. You need to get each element by index.
225 Example 1.6. redis_cmd usage
227 if(redis_cmd("srvN", "INCR cnt", "r")) {
228 # success - the incremented value is in $redis(r=>value)
229 xlog("===== $redis(r=>type) * $redis(r=>value)\n");
233 redis_cmd("srvN", "SET foo bar", "r");
235 redis_cmd("srvN", "SET ruri $ru", "r");
238 redis_cmd("srvN", "GET foo", "r");
240 # same command separated into two arguments:
241 redis_cmd("srvN", "GET %s", "foo", "r");
243 # if we have a key with spaces within it:
244 redis_cmd("srvN", "GET %s", "foo bar", "r");
246 # several values substitution:
247 redis_cmd("srvN", "HMGET %s %s %s", "key1", "field1", "field2", "r");
251 if(redis_cmd("srvN", "HMGET foo_key field1 field3", "r")) {
252 xlog("array size: $redis(r=>size)\n");
253 xlog("first values: $redis(r=>value[0]) , $redis(r=>value[1])\n");
257 4.2. redis_free(replyid)
259 Frees data in a previous reply from memory. After this function call,
260 accessing to a freed replyid returns null value.
262 It is not necessary to free a reply to use it again in a new redis_cmd
263 function. When ndb_redis module closes, all pending replies are freed
266 Example 1.7. redis_free usage
268 After a redis command call:
269 redis_cmd("srvN", "INCR cnt", "r");