C<ZRANGEBYSCORE> I<Redis> command. Additionally, all the identifiers of these
I<Sorted Sets> are kept in a I<Set> called C<collectd/values> (or
C<${prefix}/values> if the B<Prefix> option was specified) and can be retrieved
-using the C<SMEMBERS> I<Redis> command. You can specify the database to use
+using the C<SMEMBERS> I<Redis> command. You can specify the database to use
with the B<Database> parameter (default is C<0>). See
L<http://redis.io/commands#sorted_set> and L<http://redis.io/commands#set> for
details.
=item B<Database> I<Index>
-This index selects the redis database to use for writing operations. Defaults to C<0>.
+This index selects the redis database to use for writing operations. Defaults
+to C<0>.
+
+=item B<MaxSetSize> I<Items>
+
+The B<MaxSetSize> option limits the number of items that the I<Sorted Sets> can
+hold. Negative values for I<Items> sets no limit, which is the default behavior.
=back
struct timeval timeout;
char *prefix;
int database;
+ int max_set_size;
redisContext *conn;
pthread_mutex_t lock;
pthread_mutex_unlock (&node->lock);
return (-1);
}
-
+
rr = redisCommand(node->conn, "SELECT %d", node->database);
if (rr == NULL)
WARNING("SELECT command error. database:%d message:%s", node->database, node->conn->errstr);
else
freeReplyObject (rr);
+ if (node->max_set_size >= 0)
+ {
+ rr = redisCommand (node->conn, "ZREMRANGEBYRANK %s %d %d", key, 0, (-1 * node->max_set_size) - 1);
+ if (rr == NULL)
+ WARNING("SELECT command error. database:%d message:%s", node->database, 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->conn = NULL;
node->prefix = NULL;
node->database = 0;
+ node->max_set_size = -1;
pthread_mutex_init (&node->lock, /* attr = */ NULL);
status = cf_util_get_string_buffer (ci, node->name, sizeof (node->name));
else if (strcasecmp ("Database", child->key) == 0) {
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
WARNING ("write_redis plugin: Ignoring unknown config option \"%s\".",
child->key);