当前位置: 首页>>代码示例>>C++>>正文


C++ createStringObject函数代码示例

本文整理汇总了C++中createStringObject函数的典型用法代码示例。如果您正苦于以下问题:C++ createStringObject函数的具体用法?C++ createStringObject怎么用?C++ createStringObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了createStringObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: scanCallback

/* This callback is used by scanGenericCommand in order to collect elements
 * returned by the dictionary iterator into a list. */
void scanCallback(void *privdata, const dictEntry *de) {
    void **pd = (void**) privdata;
    list *keys = pd[0];
    robj *o = pd[1];
    robj *key, *val = NULL;

    if (o == NULL) {
        sds sdskey = dictGetKey(de);
        key = createStringObject(sdskey, sdslen(sdskey));
    } else if (o->type == OBJ_SET) {
        sds keysds = dictGetKey(de);
        key = createStringObject(keysds,sdslen(keysds));
    } else if (o->type == OBJ_HASH) {
        sds sdskey = dictGetKey(de);
        sds sdsval = dictGetVal(de);
        key = createStringObject(sdskey,sdslen(sdskey));
        val = createStringObject(sdsval,sdslen(sdsval));
    } else if (o->type == OBJ_ZSET) {
        sds sdskey = dictGetKey(de);
        key = createStringObject(sdskey,sdslen(sdskey));
        val = createStringObjectFromLongDouble(*(double*)dictGetVal(de),0);
    } else {
        serverPanic("Type not handled in SCAN callback.");
    }

    listAddNodeTail(keys, key);
    if (val) listAddNodeTail(keys, val);
}
开发者ID:Xwuming,项目名称:misc,代码行数:30,代码来源:db.c

示例2: z_incr_key

int z_incr_key(void *cptr, char *arg) {
	redisClient *c = (redisClient *)cptr;
	robj *argv[2], *cmd, *key;
	int i, increment_max = 1000;

	printf("z_incr_key: %s\n", arg);

	z_set(c, "incr", "1");

	cmd = createStringObject("INCR", 4);
	key = createStringObject("incr", 4);

	argv[0] = cmd;
	argv[1] = key;
	
	c->argv = argv;
	c->argc = 2;

	if(arg) {
		increment_max = atoi(arg);
	}

	for(i = 0; i < increment_max; i++) {
		incrDecrCommand(c, 1);
	}

	freeStringObject(cmd);
	freeStringObject(key);

	c->argv = NULL;
	c->argc = 0;

	return 0;
}
开发者ID:adarqui,项目名称:xedis-test,代码行数:34,代码来源:z-test-xedis.c

示例3: z_sadd

int z_sadd(void *cptr, char * name, char * val) {
	redisClient *c = (redisClient *)cptr;
	robj *argv[10], *sadd, *rkey, *rval;

	sadd = createStringObject("SADD", 4);
	rkey = createStringObject(name, strlen(name));
	rval = createStringObject(val, strlen(val));

	argv[0] = sadd;
	argv[1] = rkey;
	argv[2] = rval;

	c->argv = argv;
	c->argc = 3;

	saddCommand(c);

	c->argv = NULL;
	c->argc = 0;

	freeStringObject(sadd);
	freeStringObject(rkey);
	// FAILS! tryObjectEncoding() in t_set.c .. freeStringObject(rval);

	return 0;
}
开发者ID:adarqui,项目名称:xedis-test,代码行数:26,代码来源:z-test-xedis.c

示例4: rpoplpushHandlePush

void rpoplpushHandlePush(redisClient *origclient, redisClient *c, robj *dstkey, robj *dstobj, robj *value) {
    robj *aux;

    if (!handleClientsWaitingListPush(c,dstkey,value)) {
        /* Create the list if the key does not exist */
        if (!dstobj) {
            dstobj = createZiplistObject();
            dbAdd(c->db,dstkey,dstobj);
        } else {
            signalModifiedKey(c->db,dstkey);
        }
        listTypePush(dstobj,value,REDIS_HEAD);
        /* If we are pushing as a result of LPUSH against a key
         * watched by BLPOPLPUSH, we need to rewrite the command vector.
         * But if this is called directly by RPOPLPUSH (either directly
         * or via a BRPOPLPUSH where the popped list exists)
         * we should replicate the BRPOPLPUSH command itself. */
        if (c != origclient) {
            aux = createStringObject("LPUSH",5);
            rewriteClientCommandVector(origclient,3,aux,dstkey,value);
            decrRefCount(aux);
        } else {
            /* Make sure to always use RPOPLPUSH in the replication / AOF,
             * even if the original command was BRPOPLPUSH. */
            aux = createStringObject("RPOPLPUSH",9);
            rewriteClientCommandVector(origclient,3,aux,c->argv[1],c->argv[2]);
            decrRefCount(aux);
        }
        server.dirty++;
    }

    /* Always send the pushed value to the client. */
    addReplyBulk(c,value);
}
开发者ID:brunobnb,项目名称:brtGHost,代码行数:34,代码来源:t_list.c

示例5: z_keys_star

int z_keys_star(void *cptr, char *arg) {
	redisClient *c = (redisClient *)cptr;
	robj *argv[2], *keys, *star;

	printf("z_keys_star: %s\n", arg);

	keys = createStringObject("KEYS", 4);
	star = createStringObject("*", 1);

	argv[0] = keys;
	argv[1] = star;

	c->argv = argv;
	c->argc = 2;

	keysCommand(c);

	freeStringObject(keys);
	freeStringObject(star);

	c->argv = NULL;
	c->argc = 0;

	return 0;
}
开发者ID:adarqui,项目名称:xedis-test,代码行数:25,代码来源:z-test-xedis.c

示例6: spopCommand

void spopCommand(client *c) {
    robj *set, *ele, *aux;
    sds sdsele;
    int64_t llele;
    int encoding;

    if (c->argc == 3) {
        spopWithCountCommand(c);
        return;
    } else if (c->argc > 3) {
        addReply(c,shared.syntaxerr);
        return;
    }

    /* Make sure a key with the name inputted exists, and that it's type is
     * indeed a set */
    if ((set = lookupKeyWriteOrReply(c,c->argv[1],shared.nullbulk)) == NULL ||
        checkType(c,set,OBJ_SET)) return;

    /* Get a random element from the set */
    encoding = setTypeRandomElement(set,&sdsele,&llele);

    /* Remove the element from the set */
    if (encoding == OBJ_ENCODING_INTSET) {
        ele = createStringObjectFromLongLong(llele);
        set->ptr = intsetRemove(set->ptr,llele,NULL);
    } else {
        ele = createStringObject(sdsele,sdslen(sdsele));
        setTypeRemove(set,ele->ptr);
    }

    notifyKeyspaceEvent(NOTIFY_SET,"spop",c->argv[1],c->db->id);

    /* Replicate/AOF this command as an SREM operation */
    aux = createStringObject("SREM",4);
    rewriteClientCommandVector(c,3,aux,c->argv[1],ele);
    decrRefCount(aux);

    /* Add the element to the reply */
    addReplyBulk(c,ele);
    decrRefCount(ele);

    /* Delete the set if it's empty */
    if (setTypeSize(set) == 0) {
        dbDelete(c->db,c->argv[1]);
        notifyKeyspaceEvent(NOTIFY_GENERIC,"del",c->argv[1],c->db->id);
    }

    /* Set has been modified */
    signalModifiedKey(c->db,c->argv[1]);
    server.dirty++;
}
开发者ID:ericbbcc,项目名称:redis,代码行数:52,代码来源:t_set.c

示例7: z_set

int z_set(void *cptr, char * key, char * val) {
	redisClient *c = (redisClient *) cptr;
	robj *rkey, *rval;
	rkey = createStringObject(key, strlen(key));
	rval = createStringObject(val, strlen(val));

	setGenericCommand(c, 0, rkey, rval, NULL, 0, NULL, NULL);

	freeStringObject(rkey);
	freeStringObject(rval);

	return 0;
}
开发者ID:adarqui,项目名称:xedis-test,代码行数:13,代码来源:z-test-xedis.c

示例8: keysCommand

void keysCommand(redisClient *c) {
    dictIterator *di;
    dictEntry *de;
    sds pattern = c->argv[1]->ptr;
    int plen = sdslen(pattern);
    unsigned long numkeys = 0;
    robj *lenobj = createObject(REDIS_STRING,NULL);

    di = dictGetIterator(c->db->dict);
    addReply(c,lenobj);
    decrRefCount(lenobj);
    while((de = dictNext(di)) != NULL) {
        sds key = dictGetEntryKey(de);
        robj *keyobj;

        if ((pattern[0] == '*' && pattern[1] == '\0') ||
            stringmatchlen(pattern,plen,key,sdslen(key),0)) {
            keyobj = createStringObject(key,sdslen(key));
            if (expireIfNeeded(c->db,keyobj) == 0) {
                addReplyBulk(c,keyobj);
                numkeys++;
            }
            decrRefCount(keyobj);
        }
    }
    dictReleaseIterator(di);
    lenobj->ptr = sdscatprintf(sdsempty(),"*%lu\r\n",numkeys);
}
开发者ID:andradeandrey,项目名称:redis,代码行数:28,代码来源:db.c

示例9: lindexCommand

// LINDEX key index
// LINDEX命令的实现
void lindexCommand(client *c) {
    //以读操作取出key对象的value值
    robj *o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk);
    //如果key没找到或value对象不是列表类型则直接返回
    if (o == NULL || checkType(c,o,OBJ_LIST)) return;
    long index;
    robj *value = NULL;

    //将index参数转换为long类型的整数,保存在index中
    if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != C_OK))
        return;

    //只对编码为quicklist类型的value对象操作
    if (o->encoding == OBJ_ENCODING_QUICKLIST) {
        quicklistEntry entry;
        //将下标为index的entry节点保存到entry中
        if (quicklistIndex(o->ptr, index, &entry)) {
            if (entry.value) {  //如果vlaue是字符串类型
                //创建一个字符串类型的对象,保存value值
                value = createStringObject((char*)entry.value,entry.sz);
            } else {
                //将整型的value值转换为字符串类型并创建字符串类型的对象
                value = createStringObjectFromLongLong(entry.longval);
            }
            addReplyBulk(c,value);  //发送value对象
            decrRefCount(value);    //释放value对象
        } else {
            addReply(c,shared.nullbulk);    //如果下标为index没找到,则发送空信息
        }
    } else {
        serverPanic("Unknown list encoding");   //发送未知的列表编码类型
    }
}
开发者ID:therenine,项目名称:redis_source_annotation,代码行数:35,代码来源:t_list.c

示例10: delkeysCommand

void delkeysCommand(redisClient *c) {
    dictIterator *di;
    dictEntry *de;
    sds pattern = c->argv[1]->ptr;
    int plen = sdslen(pattern), allkeys;
    unsigned long deleted = 0;

    di = dictGetIterator(c->db->dict);
    allkeys = (pattern[0] == '*' && pattern[1] == '\0');
    while((de = dictNext(di)) != NULL) {
        sds key = dictGetEntryKey(de);
        robj *keyobj;

        if (allkeys || stringmatchlen(pattern,plen,key,sdslen(key),0)) {
            keyobj = createStringObject(key,sdslen(key));
            if (dbDelete(c->db,keyobj)) {
                touchWatchedKey(c->db,keyobj);
                server.dirty++;
                deleted++;
            }
            decrRefCount(keyobj);
        }
    }
    dictReleaseIterator(di);
    addReplyLongLong(c,deleted);
}
开发者ID:Elbandi,项目名称:redis,代码行数:26,代码来源:db.c

示例11: snprintf

/* Note: this function is defined into object.c since here it is where it
 * belongs but it is actually designed to be used just for INCRBYFLOAT */
robj *createStringObjectFromLongDouble(long double value) {
    char buf[256];
    int len;

    /* We use 17 digits precision since with 128 bit floats that precision
     * after rounding is able to represent most small decimal numbers in a way
     * that is "non surprising" for the user (that is, most small decimal
     * numbers will be represented in a way that when converted back into
     * a string are exactly the same as what the user typed.) */
#ifdef _WIN32
    /* on Windows the magic number is 15 */
    len = snprintf(buf,sizeof(buf),"%.15Lf", value);
#else
    len = snprintf(buf,sizeof(buf),"%.17Lf", value);
#endif
    /* Now remove trailing zeroes after the '.' */
    if (strchr(buf,'.') != NULL) {
        char *p = buf+len-1;
        while(*p == '0') {
            p--;
            len--;
        }
        if (*p == '.') len--;
    }
    return createStringObject(buf,len);
}
开发者ID:mrtnzlml-archive,项目名称:Real-time-WS,代码行数:28,代码来源:object.c

示例12: lindexCommand

void lindexCommand(redisClient *c) {
    robj *o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk);
    if (o == NULL || checkType(c,o,REDIS_LIST)) return;
    int index = atoi(c->argv[2]->ptr);
    robj *value = NULL;

    if (o->encoding == REDIS_ENCODING_ZIPLIST) {
        unsigned char *p;
        unsigned char *vstr;
        unsigned int vlen;
        long long vlong;
        p = ziplistIndex(o->ptr,index);
        if (ziplistGet(p,&vstr,&vlen,&vlong)) {
            if (vstr) {
                value = createStringObject((char*)vstr,vlen);
            } else {
                value = createStringObjectFromLongLong(vlong);
            }
            addReplyBulk(c,value);
            decrRefCount(value);
        } else {
            addReply(c,shared.nullbulk);
        }
    } else if (o->encoding == REDIS_ENCODING_LINKEDLIST) {
        listNode *ln = listIndex(o->ptr,index);
        if (ln != NULL) {
            value = listNodeValue(ln);
            addReplyBulk(c,value);
        } else {
            addReply(c,shared.nullbulk);
        }
    } else {
        redisPanic("Unknown list encoding");
    }
}
开发者ID:brunobnb,项目名称:brtGHost,代码行数:35,代码来源:t_list.c

示例13: execCommandPropagateMulti

/* Send a MULTI command to all the slaves and AOF file. Check the execCommand
 * implementation for more information. */
void execCommandPropagateMulti(client *c) {
    robj *multistring = createStringObject("MULTI",5);

    propagate(server.multiCommand,c->db->id,&multistring,1,
              PROPAGATE_AOF|PROPAGATE_REPL);
    decrRefCount(multistring);
}
开发者ID:sqlfocus,项目名称:redis-note,代码行数:9,代码来源:multi.c

示例14: lindexCommand

void lindexCommand(client *c) {
    robj *o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk);
    if (o == NULL || checkType(c,o,OBJ_LIST)) return;
    long index;
    robj *value = NULL;

    if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != C_OK))
        return;

    if (o->encoding == OBJ_ENCODING_QUICKLIST) {
        quicklistEntry entry;
        if (quicklistIndex(o->ptr, index, &entry)) {
            if (entry.value) {
                value = createStringObject((char*)entry.value,entry.sz);
            } else {
                value = createStringObjectFromLongLong(entry.longval);
            }
            addReplyBulk(c,value);
            decrRefCount(value);
        } else {
            addReply(c,shared.nullbulk);
        }
    } else {
        serverPanic("Unknown list encoding");
    }
}
开发者ID:RealHacker,项目名称:redis-plus,代码行数:26,代码来源:t_list.c

示例15: scriptCommand

void scriptCommand(rliteClient *c) {
	if (c->argc == 2 && !strcasecmp(c->argv[1],"flush")) {
		scriptingReset();
		c->reply = createStatusObject(RLITE_STR_OK);
	} else if (c->argc >= 2 && !strcasecmp(c->argv[1],"exists")) {
		int j;

		c->reply = createArrayObject(c->argc - 2);
		for (j = 2; j < c->argc; j++) {
			c->reply->element[j - 2] = createLongLongObject(getScript(c, c->argv[j], NULL, NULL) == RL_OK ? 1 : 0);
		}
	} else if (c->argc == 3 && !strcasecmp(c->argv[1],"load")) {
		char sha[41];

		sha1hex(sha,c->argv[2],c->argvlen[2]);
		setScript(c, c->argv[2], c->argvlen[2]);
		c->reply = createStringObject(sha,40);
	} else if (c->argc == 2 && !strcasecmp(c->argv[1],"kill")) {
		if (lua_caller == NULL) {
			c->reply = createCStringObject("NOTBUSY No scripts in execution right now.\r\n");
		} else if (lua_write_dirty) {
			c->reply = createCStringObject("UNKILLABLE Sorry the script already executed write commands against the dataset. You can either wait the script termination or kill the server in a hard way using the SHUTDOWN NOSAVE command.\r\n");
		} else {
			lua_kill = 1;
			c->reply = createStatusObject(RLITE_STR_OK);
		}
	} else {
		c->reply = createErrorObject("ERR Unknown SCRIPT subcommand or wrong # of args.");
	}
}
开发者ID:jqk6,项目名称:rlite,代码行数:30,代码来源:scripting.c


注:本文中的createStringObject函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。