本文整理汇总了C++中dictSize函数的典型用法代码示例。如果您正苦于以下问题:C++ dictSize函数的具体用法?C++ dictSize怎么用?C++ dictSize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dictSize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: closeTimedoutClients
void closeTimedoutClients(void) {
redisClient *c;
listNode *ln;
time_t now = time(NULL);
listIter li;
listRewind(server.clients,&li);
while ((ln = listNext(&li)) != NULL) {
c = listNodeValue(ln);
if (server.maxidletime &&
!(c->flags & REDIS_SLAVE) && /* no timeout for slaves */
!(c->flags & REDIS_MASTER) && /* no timeout for masters */
dictSize(c->pubsub_channels) == 0 && /* no timeout for pubsub */
listLength(c->pubsub_patterns) == 0 &&
(now - c->lastinteraction > server.maxidletime))
{
redisLog(REDIS_VERBOSE,"Closing idle client");
freeClient(c);
} else if (c->flags & REDIS_BLOCKED) {
if (c->blockingto != 0 && c->blockingto < now) {
addReply(c,shared.nullmultibulk);
unblockClientWaitingData(c);
}
}
}
}
示例2: unblockClientWaitingData
/* Unblock a client that's waiting in a blocking operation such as BLPOP.
* You should never call this function directly, but unblockClient() instead. */
void unblockClientWaitingData(redisClient *c) {
dictEntry *de;
dictIterator *di;
list *l;
redisAssertWithInfo(c,NULL,dictSize(c->bpop.keys) != 0);
di = dictGetIterator(c->bpop.keys);
/* The client may wait for multiple keys, so unblock it for every key. */
while((de = dictNext(di)) != NULL) {
robj *key = dictGetKey(de);
/* Remove this client from the list of clients waiting for this key. */
l = dictFetchValue(c->db->blocking_keys,key);
redisAssertWithInfo(c,key,l != NULL);
listDelNode(l,listSearchKey(l,c));
/* If the list is empty we need to remove it to avoid wasting memory */
if (listLength(l) == 0)
dictDelete(c->db->blocking_keys,key);
}
dictReleaseIterator(di);
/* Cleanup the client structure */
dictEmpty(c->bpop.keys,NULL);
if (c->bpop.target) {
decrRefCount(c->bpop.target);
c->bpop.target = NULL;
}
}
示例3: unblockClientWaitingData
//解阻塞一个正在阻塞中的client
void unblockClientWaitingData(client *c) {
dictEntry *de;
dictIterator *di;
list *l;
serverAssertWithInfo(c,NULL,dictSize(c->bpop.keys) != 0);
//创建一个字典的迭代器,指向的是造成client阻塞的键所组成的字典
di = dictGetIterator(c->bpop.keys);
/* The client may wait for multiple keys, so unblock it for every key. */
//因为client可能被多个key所阻塞,所以要遍历所有的键
while((de = dictNext(di)) != NULL) {
robj *key = dictGetKey(de); //获得key对象
/* Remove this client from the list of clients waiting for this key. */
//根据key找到对应的列表类型值,值保存着被阻塞的client,从中找c->db->blocking_keys中寻找
l = dictFetchValue(c->db->blocking_keys,key);
serverAssertWithInfo(c,key,l != NULL);
// 将阻塞的client从列表中移除
listDelNode(l,listSearchKey(l,c));
/* If the list is empty we need to remove it to avoid wasting memory */
//如果当前列表为空了,则从c->db->blocking_keys中将key删除
if (listLength(l) == 0)
dictDelete(c->db->blocking_keys,key);
}
dictReleaseIterator(di); //释放迭代器
/* Cleanup the client structure */
//清空bpop.keys的所有节点
dictEmpty(c->bpop.keys,NULL);
//如果保存有新添加的元素,则应该释放
if (c->bpop.target) {
decrRefCount(c->bpop.target);
c->bpop.target = NULL;
}
}
示例4: flushdbCommand
void flushdbCommand(redisClient *c) {
server.dirty += dictSize(c->db->dict);
signalFlushedDb(c->db->id);
dictEmpty(c->db->dict,NULL);
dictEmpty(c->db->expires,NULL);
addReply(c,shared.ok);
}
示例5: pubsubSubscribeChannel
/* Subscribe a client to a channel. Returns 1 if the operation succeeded, or
* 0 if the client was already subscribed to that channel. */
int pubsubSubscribeChannel(redisClient *c, robj *channel) {
struct dictEntry *de;
list *clients = NULL;
int retval = 0;
/* Add the channel to the client -> channels hash table */
if (dictAdd(c->pubsub_channels,channel,NULL) == DICT_OK) {
retval = 1;
incrRefCount(channel);
/* Add the client to the channel -> list of clients hash table */
de = dictFind(server.pubsub_channels,channel);
if (de == NULL) {
clients = listCreate();
dictAdd(server.pubsub_channels,channel,clients);
incrRefCount(channel);
} else {
clients = dictGetEntryVal(de);
}
listAddNodeTail(clients,c);
}
/* Notify the client */
addReply(c,shared.mbulk3);
addReply(c,shared.subscribebulk);
addReplyBulk(c,channel);
addReplyLongLong(c,dictSize(c->pubsub_channels)+listLength(c->pubsub_patterns));
return retval;
}
示例6: pubsubUnsubscribePattern
/* Unsubscribe a client from a channel. Returns 1 if the operation succeeded, or
* 0 if the client was not subscribed to the specified channel. */
int pubsubUnsubscribePattern(redisClient *c, robj *pattern, int notify) {
listNode *ln;
pubsubPattern pat;
int retval = 0;
incrRefCount(pattern); /* Protect the object. May be the same we remove */
if ((ln = listSearchKey(c->pubsub_patterns,pattern)) != NULL) {
retval = 1;
listDelNode(c->pubsub_patterns,ln);
pat.client = c;
pat.pattern = pattern;
ln = listSearchKey(server.pubsub_patterns,&pat);
listDelNode(server.pubsub_patterns,ln);
}
/* Notify the client */
if (notify) {
addReply(c,shared.mbulk3);
addReply(c,shared.punsubscribebulk);
addReplyBulk(c,pattern);
addReplyLongLong(c,dictSize(c->pubsub_channels)+
listLength(c->pubsub_patterns));
}
decrRefCount(pattern);
return retval;
}
示例7: counterMaybeResend
/* Check if we need to resend our prediction of the counter to some nodes. */
void counterMaybeResend(counter *cntr) {
clusterNode *node;
int i;
/* No acks to send? */
if (cntr->want_acks == NULL || dictSize(cntr->want_acks) == 0) {
return;
}
/* Too soon? */
if (cntr->updated > mstime()-5000) {
return;
}
/* Only check reachable nodes that have a valid link. */
for (i = 0; i < server.cluster->reachable_nodes_count; i++) {
node = server.cluster->reachable_nodes[i];
if (node->link == NULL) continue;
if (dictFind(cntr->want_acks, node->name) != NULL) {
clusterSendShardToNode(cntr, node);
}
}
}
示例8: touchWatchedKey
/*
* “碰触”(touch)给定 key ,如果这个 key 正在被监视的话,
* 让监视它的客户端在执行 EXEC 命令时失败。
*
* T = O(N)
*/
void touchWatchedKey(redisDb *db, robj *key)
{
list *clients;
listIter li;
listNode *ln;
// 如果数据库中没有任何 key 被监视,那么直接返回
if (dictSize(db->watched_keys) == 0) return;
// 取出数据库中所有监视给定 key 的客户端
clients = dictFetchValue(db->watched_keys, key);
if (!clients) return;
/* Mark all the clients watching this key as REDIS_DIRTY_CAS */
/* Check if we are already watching for this key */
// 打开所有监视这个 key 的客户端的 REDIS_DIRTY_CAS 状态
// O(N)
listRewind(clients,&li);
while((ln = listNext(&li)))
{
redisClient *c = listNodeValue(ln);
c->flags |= REDIS_DIRTY_CAS;
}
}
示例9: htNeedsResize
int htNeedsResize(dict *dict) {
long long size, used;
size = dictSlots(dict);
used = dictSize(dict);
return (size && used && size > DICT_HT_INITIAL_SIZE &&
(used*100/size < HASHTABLE_MIN_FILL));
}
示例10: roDBDictSize
int roDBDictSize(int id) {
if (server.isBackgroundSaving != 0) {
if (server.cowSaveDbExt[id].dictArray != NULL) {
return server.cowSaveDbExt[id].dictArray->numele;
}
}
return dictSize(server.db[id].dict);
}
示例11: flushdbCommand
void flushdbCommand(client *c) {
server.dirty += dictSize(c->db->dict);
signalFlushedDb(c->db->id);
dictEmpty(c->db->dict,NULL);
dictEmpty(c->db->expires,NULL);
if (server.cluster_enabled) slotToKeyFlush();
addReply(c,shared.ok);
}
示例12: flushdbCommand
void flushdbCommand(redisClient *c) {
server.dirty += dictSize(c->db->dict);
signalFlushedDb(c->db->id);
dictEmpty(c->db->dict);
dictEmpty(c->db->expires);
if (server.ds_enabled) dsFlushDb(c->db->id);
addReply(c,shared.ok);
}
示例13: scriptNameCommand
/* scriptNameCommand() has compound sub-arguments, so it looks slightly more
* convoluted than it actually is. Just read each if/else branch as
* if it were an individual command. */
void scriptNameCommand(redisClient *c) {
char *req = c->argv[1]->ptr;
sds script_name = c->argv[2]->ptr;
if (c->argc == 4 && !strcasecmp(req, "set")) {
sds target_sha = c->argv[3]->ptr;
if (sdslen(target_sha) != 40 ||
dictFind(server.lua_scripts,target_sha) == NULL) {
addReply(c, g.err.nosha);
return;
}
/* If name doesn't exist, dictReplace == dictAdd */
dictReplace(g.names, script_name, target_sha);
addReplyBulkCBuffer(c, script_name, sdslen(script_name));
} else if (c->argc == 3 && !strcasecmp(req, "get")) {
sds found;
if ((found = dictFetchValue(g.names, script_name))) {
addReplyBulkCBuffer(c, found, sdslen(found));
} else {
addReply(c, g.err.noname);
}
} else if (c->argc == 2 && !strcasecmp(req, "getall")) {
dictIterator *di;
dictEntry *de;
unsigned long sz = dictSize(g.names);
if (!sz) {
addReply(c, shared.emptymultibulk);
return;
}
/* Multiply by 2 because the size of the dict is the number of keys.
* We are returning keys *and* values, so length is dictSize * 2 */
addReplyMultiBulkLen(c, sz * 2);
di = dictGetIterator(g.names);
while ((de = dictNext(di))) {
addReplyBulkCString(c, dictGetKey(de));
addReplyBulkCString(c, dictGetVal(de));
}
dictReleaseIterator(di);
} else if (c->argc == 3 && !strcasecmp(req, "del")) {
sds deleted;
if ((deleted = dictFetchValue(g.names, script_name))) {
dictDelete(g.names, script_name);
addReplyBulkCBuffer(c, deleted, sdslen(deleted));
} else {
addReply(c, g.err.noname);
}
} else {
addReplyError(c, "Unknown scriptName subcommand or arg count");
}
}
示例14: rdb_save_triggles
void rdb_save_triggles(rio *rdb)
{
//save event
//db_num int int int int
//db
//scripts_num
//key event lua_scripts
//key event lua_scripts
//.......
dictIterator *di = NULL;
dictEntry *de;
int i=0;
for(i=0;i<server.dbnum;i++){
int eventid=server.bridge_db.bridge_event[i];
rioWrite(rdb,&eventid,4);
}
for(i=0;i<server.dbnum;i++)
{
dict *d = server.bridge_db.triggle_scipts[i];
int mysize=dictSize(d);
rioWrite(rdb,&mysize,4);
if (dictSize(d) == 0) continue;
di = dictGetSafeIterator(d);
if (!di) {
return ;
}
/* Iterate this DB writing every entry */
while((de = dictNext(di)) != NULL) {
sds keystr = dictGetKey(de);
robj key;
initStaticStringObject(key,keystr);
if (rdbSaveStringObject(rdb,&key) == -1) return;
struct bridge_db_triggle_t * tmptrg=dictGetVal(de);
int event_id=tmptrg->event;
rioWrite(rdb,&event_id,4);
int db_id=tmptrg->dbid;
rioWrite(rdb,&db_id,4);
if (rdbSaveObjectType(rdb,tmptrg->lua_scripts) == -1) return ;
if (rdbSaveObject(rdb,tmptrg->lua_scripts) == -1) return ;
}
}
if (di) dictReleaseIterator(di);
}
示例15: setTypeSize
unsigned long setTypeSize(robj *subject) {
if (subject->encoding == REDIS_ENCODING_HT) {
return dictSize((dict*)subject->ptr);
} else if (subject->encoding == REDIS_ENCODING_INTSET) {
return intsetLen((intset*)subject->ptr);
} else {
redisPanic("Unknown set encoding");
}
}