summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ebf73b6)
raw | patch | inline | side by side (parent: ebf73b6)
author | Tomofumi Hayashi <tohayash@redhat.com> | |
Thu, 21 Sep 2017 09:10:30 +0000 (18:10 +0900) | ||
committer | Tomofumi Hayashi <tohayash@redhat.com> | |
Mon, 25 Sep 2017 15:25:14 +0000 (00:25 +0900) |
This change introduces max_set_duration, the duration for the value
as max_set_size. max_set_size can keep the db size, however, sometime
max_set_size allows to contain old data. max_set_duration can keep
the latest data.
as max_set_size. max_set_size can keep the db size, however, sometime
max_set_size allows to contain old data. max_set_duration can keep
the latest data.
src/write_redis.c | patch | blob | history |
diff --git a/src/write_redis.c b/src/write_redis.c
index 5a029de2761a4c75c618ea8f11cd448831c1e1ff..7dd5029ce1a6da94c0d4d1773c5a7eaa91beb198 100644 (file)
--- a/src/write_redis.c
+++ b/src/write_redis.c
char *prefix;
int database;
int max_set_size;
+ int max_set_duration;
_Bool store_rates;
redisContext *conn;
freeReplyObject(rr);
}
+ if (node->max_set_duration > 0) {
+ /*
+ * remove element, scored less than 'current-max_set_duration'
+ * '(%d' indicates 'less than' in redis CLI.
+ */
+ rr = redisCommand(node->conn, "ZREMRANGEBYSCORE %s -1 (%d", key,
+ (time - node->max_set_duration) + 1);
+ if (rr == NULL)
+ WARNING("ZREMRANGEBYSCORE command error. key:%s message:%s", key,
+ node->conn->errstr);
+ else
+ freeReplyObject(rr);
+ }
+
/* TODO(octo): This is more overhead than necessary. Use the cache and
* metadata to determine if it is a new metric and call SADD only once for
* each metric. */
node->prefix = NULL;
node->database = 0;
node->max_set_size = -1;
+ node->max_set_duration = -1;
node->store_rates = 1;
pthread_mutex_init(&node->lock, /* attr = */ NULL);
status = cf_util_get_int(child, &node->database);
} else if (strcasecmp("MaxSetSize", child->key) == 0) {
status = cf_util_get_int(child, &node->max_set_size);
+ } else if (strcasecmp("MaxSetDuration", child->key) == 0) {
+ status = cf_util_get_int(child, &node->max_set_duration);
} else if (strcasecmp("StoreRates", child->key) == 0) {
status = cf_util_get_boolean(child, &node->store_rates);
} else