From: antirez Date: Tue, 17 Jan 2012 11:43:01 +0000 (+0100) Subject: Introduced three client limit classes: normal, slave, pubsub X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/498dc5557c31fc9a65a36f2e8da9accfa72fbc5a Introduced three client limit classes: normal, slave, pubsub --- diff --git a/src/networking.c b/src/networking.c index 61f84920..47fbcc58 100644 --- a/src/networking.c +++ b/src/networking.c @@ -1149,3 +1149,18 @@ unsigned long getClientOutputBufferMemoryUsage(redisClient *c) { return c->reply_bytes + (list_item_size*listLength(c->reply)); } + +/* Get the class of a client, used in order to envorce limits to different + * classes of clients. + * + * The function will return one of the following: + * REDIS_CLIENT_LIMIT_CLASS_NORMAL -> Normal client + * REDIS_CLIENT_LIMIT_CLASS_SLAVE -> Slave or client executing MONITOR command + * REDIS_CLIENT_LIMIT_CLASS_PUBSUB -> Client subscribed to Pub/Sub channels + */ +int getClientLimitClass(redisClient *c) { + if (c->flags & REDIS_SLAVE) return REDIS_CLIENT_LIMIT_CLASS_SLAVE; + if (dictSize(c->pubsub_channels) || listLength(c->pubsub_patterns)) + return REDIS_CLIENT_LIMIT_CLASS_PUBSUB; + return REDIS_CLIENT_LIMIT_CLASS_NORMAL; +} diff --git a/src/redis.h b/src/redis.h index 43082975..42ade8fc 100644 --- a/src/redis.h +++ b/src/redis.h @@ -146,6 +146,12 @@ #define REDIS_REQ_INLINE 1 #define REDIS_REQ_MULTIBULK 2 +/* Client classes for client limits, currently used only for + * the max-client-output-buffer limit implementation. */ +#define REDIS_CLIENT_LIMIT_CLASS_NORMAL 0 +#define REDIS_CLIENT_LIMIT_CLASS_SLAVE 1 +#define REDIS_CLIENT_LIMIT_CLASS_PUBSUB 2 + /* Slave replication state - slave side */ #define REDIS_REPL_NONE 0 /* No active replication */ #define REDIS_REPL_CONNECT 1 /* Must connect to master */