Module: kamailio
Branch: master
Commit: 201ba078948183ce7b42fcedc8cf0989b4d84ae3
URL: 
https://github.com/kamailio/kamailio/commit/201ba078948183ce7b42fcedc8cf0989b4d84ae3

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2025-07-15T11:54:27+02:00

ndb_redis: per server attributes for connect and command timeouts

---

Modified: src/modules/ndb_redis/redis_client.c
Modified: src/modules/ndb_redis/redis_client.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/201ba078948183ce7b42fcedc8cf0989b4d84ae3.diff
Patch: 
https://github.com/kamailio/kamailio/commit/201ba078948183ce7b42fcedc8cf0989b4d84ae3.patch

---

diff --git a/src/modules/ndb_redis/redis_client.c 
b/src/modules/ndb_redis/redis_client.c
index 4898673bfbc..24cff78e751 100644
--- a/src/modules/ndb_redis/redis_client.c
+++ b/src/modules/ndb_redis/redis_client.c
@@ -92,14 +92,8 @@ int redisc_init(void)
        int i, row;
        redisc_server_t *rsrv = NULL;
        param_t *pit = NULL;
-       struct timeval tv_conn;
-       struct timeval tv_cmd;
-
-       tv_conn.tv_sec = (int)redis_connect_timeout_param / 1000;
-       tv_conn.tv_usec = (int)(redis_connect_timeout_param % 1000) * 1000;
-
-       tv_cmd.tv_sec = (int)redis_cmd_timeout_param / 1000;
-       tv_cmd.tv_usec = (int)(redis_cmd_timeout_param % 1000) * 1000;
+       struct timeval tv_conn = {0};
+       struct timeval tv_cmd = {0};
 
        if(_redisc_srv_list == NULL) {
                LM_ERR("no redis servers defined\n");
@@ -119,6 +113,21 @@ int redisc_init(void)
                memset(pass, 0, sizeof(pass));
                memset(unix_sock_path, 0, sizeof(unix_sock_path));
 
+               if(rsrv->connect_timeout > 0) {
+                       tv_conn.tv_sec = (long)(rsrv->connect_timeout / 1000);
+                       tv_conn.tv_usec = (int)(rsrv->connect_timeout % 1000) * 
1000;
+               } else {
+                       tv_conn.tv_sec = (long)(redis_connect_timeout_param / 
1000);
+                       tv_conn.tv_usec = (int)(redis_connect_timeout_param % 
1000) * 1000;
+               }
+               if(rsrv->command_timeout > 0) {
+                       tv_cmd.tv_sec = (long)(rsrv->command_timeout / 1000);
+                       tv_cmd.tv_usec = (int)(rsrv->command_timeout % 1000) * 
1000;
+               } else {
+                       tv_cmd.tv_sec = (long)(redis_cmd_timeout_param / 1000);
+                       tv_cmd.tv_usec = (int)(redis_cmd_timeout_param % 1000) 
* 1000;
+               }
+
                for(pit = rsrv->attrs; pit; pit = pit->next) {
                        if(pit->name.len == 4 && strncmp(pit->name.s, "unix", 
4) == 0) {
                                snprintf(unix_sock_path, sizeof(unix_sock_path) 
- 1, "%.*s",
@@ -408,7 +417,12 @@ int redisc_add_server(char *spec)
                if(pit->name.len == 4 && strncmp(pit->name.s, "name", 4) == 0) {
                        rsrv->sname = &pit->body;
                        rsrv->hname = get_hash1_raw(rsrv->sname->s, 
rsrv->sname->len);
-                       break;
+               } else if(pit->name.len == 15
+                                 && strncmp(pit->name.s, "connect_timeout", 
15) == 0) {
+                       str2sint(&pit->body, &rsrv->connect_timeout);
+               } else if(pit->name.len == 15
+                                 && strncmp(pit->name.s, "command_timeout", 
15) == 0) {
+                       str2sint(&pit->body, &rsrv->command_timeout);
                }
        }
        if(rsrv->sname == NULL) {
@@ -470,11 +484,20 @@ int redisc_reconnect_server(redisc_server_t *rsrv)
        struct timeval tv_conn;
        struct timeval tv_cmd;
 
-       tv_conn.tv_sec = (int)redis_connect_timeout_param / 1000;
-       tv_conn.tv_usec = (int)(redis_connect_timeout_param % 1000) * 1000;
-
-       tv_cmd.tv_sec = (int)redis_cmd_timeout_param / 1000;
-       tv_cmd.tv_usec = (int)(redis_cmd_timeout_param % 1000) * 1000;
+       if(rsrv->connect_timeout > 0) {
+               tv_conn.tv_sec = (long)(rsrv->connect_timeout / 1000);
+               tv_conn.tv_usec = (int)(rsrv->connect_timeout % 1000) * 1000;
+       } else {
+               tv_conn.tv_sec = (long)(redis_connect_timeout_param / 1000);
+               tv_conn.tv_usec = (int)(redis_connect_timeout_param % 1000) * 
1000;
+       }
+       if(rsrv->command_timeout > 0) {
+               tv_cmd.tv_sec = (long)(rsrv->command_timeout / 1000);
+               tv_cmd.tv_usec = (int)(rsrv->command_timeout % 1000) * 1000;
+       } else {
+               tv_cmd.tv_sec = (long)(redis_cmd_timeout_param / 1000);
+               tv_cmd.tv_usec = (int)(redis_cmd_timeout_param % 1000) * 1000;
+       }
 
        memset(addr, 0, sizeof(addr));
        port = 6379;
diff --git a/src/modules/ndb_redis/redis_client.h 
b/src/modules/ndb_redis/redis_client.h
index 0a5a3d82dfb..c97a5791d6f 100644
--- a/src/modules/ndb_redis/redis_client.h
+++ b/src/modules/ndb_redis/redis_client.h
@@ -81,6 +81,8 @@ typedef struct redisc_server
 {
        str *sname;
        unsigned int hname;
+       int connect_timeout;
+       int command_timeout;
        param_t *attrs;
        char *spec;
        redisContext *ctxRedis;

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to