Browse Source

* backend/redis : changeable interval between pings of redis server

master
Alex 'AdUser' Z 8 years ago
parent
commit
6b04d1f8fb
  1. 1
      configs/conf-available/10-backend-redis.conf
  2. 12
      src/backends/redis.c

1
configs/conf-available/10-backend-redis.conf

@ -2,6 +2,7 @@
load = libf2b_backend_redis.so
shared = yes
timeout = 2
ping = 5
host = 127.0.0.1
port = 6379
database = 0

12
src/backends/redis.c

@ -28,6 +28,8 @@ struct _config {
char error[256];
bool shared;
time_t timeout;
uint8_t ping_num; /*< current number of ping() call */
uint8_t ping_max; /*< max ping() calls before actually pinginig redis server */
uint8_t database;
char password[32];
char host[32];
@ -129,6 +131,10 @@ config(cfg_t *cfg, const char *key, const char *value) {
cfg->port = atoi(value);
return true;
}
if (strcmp(key, "ping") == 0) {
cfg->ping_max = atoi(value);
return true;
}
if (strcmp(key, "database") == 0) {
cfg->database = atoi(value);
return true;
@ -238,6 +244,12 @@ ping(cfg_t *cfg) {
return false;
}
cfg->ping_num++;
if (cfg->ping_num < cfg->ping_max)
return true; /* skip this try */
/* max empty calls reached, make real ping */
cfg->ping_num = 0;
redisReply *reply = redisCommand(cfg->conn, "PING");
if (reply) {
bool result = true;

Loading…
Cancel
Save