本文整理汇总了C++中freeReplyObject函数的典型用法代码示例。如果您正苦于以下问题:C++ freeReplyObject函数的具体用法?C++ freeReplyObject怎么用?C++ freeReplyObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了freeReplyObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_range_long
int test_range_long(int frompos, int slen, int count)
{
int fd;
int endpos = frompos + slen;
struct timeval start, end;
redisReply *ret;
ret = redisConnect(&fd, "127.0.0.1", 6379);
if (NULL != ret) {
DINFO("connect error! %s\n", ret->reply);
return -1;
}
int i;
char *key = "haha";
char val[32];
char buf[128];
gettimeofday(&start, NULL);
for (i = 0; i < count; i++) {
sprintf(buf, "LRANGE %s %d %d", key, frompos, endpos - 1);
//ret = redisCommand(fd, "LRANGE %s %d %d", key, frompos, slen);
ret = redisCommand(fd, buf);
if (ret->type != REDIS_REPLY_ARRAY) {
DINFO("lrange error! %d, %s\n", ret->type, ret->reply);
return -2;
}
if (ret->elements != slen) {
DERROR("lrange count error: %d, len:%d\n", ret->elements, slen);
}
freeReplyObject(ret);
}
gettimeofday(&end, NULL);
unsigned int tmd = timediff(&start, &end);
double speed = ((double)count / tmd) * 1000000;
DINFO("range long use time: %u, speed: %.2f\n", tmd, speed);
close(fd);
return (int)speed;
}
示例2: _do_redis_command
long long _do_redis_command( const char ** args,const size_t * argvlen, size_t arg_count) {
pthread_mutex_lock(&sredisContext_mutex);
redisContext *c = NULL;
redisReply *reply;
c = (redisContext*)_redis_context_init();
if (!c) {
info_print("_redis_context_init return null, connect failed\n");
pthread_mutex_unlock(&sredisContext_mutex);
return -1;
}
debug_print("%s %s %s\n",args[0] ,args[1],args[2]);
reply = redisCommandArgv(c,arg_count,args,argvlen);
if(!reply) {
c = (redisContext*)_redis_context_reinit();
if (!c) {
info_print("_do_redis_command, Cannot reconnect to redis\n ");
pthread_mutex_unlock(&sredisContext_mutex);
return -1;
}
reply = redisCommandArgv(c,arg_count,args,argvlen);
if (!reply) {
info_print("_do_redis_command, reconnect to redis and re-execute redisCommandArgv failed\n ");
pthread_mutex_unlock(&sredisContext_mutex);
return -1;
}
}
if(reply) {
freeReplyObject(reply);
}
pthread_mutex_unlock(&sredisContext_mutex);
return 0;
}
示例3: hashes
//-------------------------------------------------------------------------------------
bool KBEEntityLogTableRedis::queryEntity(DBInterface * dbi, DBID dbid, EntityLog& entitylog, ENTITY_SCRIPT_UID entityType)
{
/*
kbe_entitylog:dbid:entityType = hashes(entityID, ip, port, componentID)
*/
redisReply* pRedisReply = NULL;
try
{
static_cast<DBInterfaceRedis*>(dbi)->query(fmt::format("HMGET kbe_entitylog:{}:{} entityID ip port componentID",
dbid, entityType), &pRedisReply, false);
}
catch(...)
{
}
entitylog.dbid = dbid;
entitylog.componentID = 0;
entitylog.entityID = 0;
entitylog.ip[0] = '\0';
entitylog.port = 0;
if(pRedisReply)
{
if(pRedisReply->type == REDIS_REPLY_ARRAY)
{
if(RedisHelper::check_array_results(pRedisReply))
{
StringConv::str2value(entitylog.entityID, pRedisReply->element[0]->str);
kbe_snprintf(entitylog.ip, MAX_IP, "%s", pRedisReply->element[1]->str);
StringConv::str2value(entitylog.port, pRedisReply->element[2]->str);
StringConv::str2value(entitylog.componentID, pRedisReply->element[3]->str);
}
}
freeReplyObject(pRedisReply);
}
return entitylog.componentID > 0;
}
示例4: redis_pull
int redis_pull(char *redisqueuename, void *buf,
int maxload, size_t obj_size, int *numloaded, const char* cmd)
{
assert(rctx);
long elems_in_redis = redis_get_sizeof_list(redisqueuename);
long num_to_add = MIN(elems_in_redis, maxload);
log_info("redis", "INFO: redis load called on %s. Transfering %li "
"of %li elements to in-memory queue.",
redisqueuename,
num_to_add, elems_in_redis);
for(int i=0; i < num_to_add; i++) {
redisAppendCommand(rctx, "%s %s", cmd, redisqueuename);
}
for(int i=0; i < num_to_add; i++) {
redisReply *reply;
int rc = redisGetReply(rctx, (void**) &reply);
if (rc != REDIS_OK) {
log_fatal("redis", "response from redis != REDIS_OK");
return -1;
}
if (!reply) {
log_fatal("redis", "no reply provided by redis.");
return -1;
}
if (reply->type != REDIS_REPLY_STRING) {
log_fatal("redis",
"unxpected reply type from redis.");
return -1;
}
if ((size_t)reply->len != obj_size) {
log_fatal("redis", "ERROR: unexpected lengthed "
"object provided by redis.\n");
return -1;
}
memcpy((void*)((intptr_t)buf+i*obj_size), reply->str, obj_size);
freeReplyObject(reply);
}
*numloaded = num_to_add;
return 0;
}
示例5: lrange
// redis lrange: get list from start to end -- with R serialization
Rcpp::List lrange(std::string key, int start, int end) {
// uses binary protocol, see hiredis doc at github
redisReply *reply =
static_cast<redisReply*>(redisCommand(prc_, "LRANGE %s %d %d",
key.c_str(), start, end));
unsigned int len = reply->elements;
//Rcpp::Rcout << "Seeing " << len << " elements\n";
Rcpp::List x(len);
for (unsigned int i = 0; i < len; i++) {
//Rcpp::Rcout << " Seeing size " << reply->element[i]->len << "\n";
int nc = reply->element[i]->len;
Rcpp::RawVector res(nc);
memcpy(res.begin(), reply->element[i]->str, nc);
SEXP obj = unserializeFromRaw(res);
x[i] = obj;
}
freeReplyObject(reply);
return(x);
}
示例6: main
int main()
{
struct timeval timeout = {2, 0};
redisContext *pRedisContext = (redisContext*)redisConnectWithTimeout("127.0.0.1", 6379, timeout);
if((pRedisContext == NULL) || (pRedisContext->err))
{
if(pRedisContext)
{
std::cout << "connect error:" << pRedisContext->errstr << std::endl;
}else{
std::cout << "connect error: can't allocate redis context" << std::endl;
}
return -1;
}
redisReply *pRedisReply = (redisReply*)redisCommand(pRedisContext, "INFO");
std::cout << pRedisReply->str << std::endl;
freeReplyObject(pRedisReply);
return 0;
}
示例7: main
int main(int argc, char *argv[]) {
unsigned int j;
redisContext *c;
redisReply *reply;
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
c = redisConnectWithTimeout((char*)"127.0.0.2", 6379, timeout);
if (c->err) {
printf("Connection error: %s\n", c->errstr);
exit(1);
}
for (int i=0; i < sizeof(testStrings)/sizeof(char*); i++) {
double score = atof_raw(testStrings[i]);
reply = redisCommand(c, "ZADD %s %.20e %s", "ascii|test", score, testStrings[i]);
printf("result: %s\n", reply->str);
freeReplyObject(reply);
}
return 0;
}
示例8: PROXY_NOTUSED
void *sumIntegerKeyProc(proxyContext *p, int argc, char **argv, redisKeyInfo *keyInfo){
PROXY_NOTUSED(keyInfo);
redisContext *c;
redisReply *replyAll;
replyAll = createReplyObject(REDIS_REPLY_INTEGER);
if( replyAll ){
for( int i = 0; i < p->count; i++ ){
redisReply *reply;
c = getRedisContextWithIdx( p, i );
reply = proxyCommandArgvList( p, c, argc, (const char **)argv );
int value = 0;
if( reply ) {
value = reply->integer;
freeReplyObject(reply);
}
replyAll->integer += value;
}
}
return replyAll;
}
示例9: mrb_redis_hkeys
mrb_value mrb_redis_hkeys(mrb_state *mrb, mrb_value self)
{
mrb_value key, array = mrb_nil_value();
redisContext *rc = DATA_PTR(self);
mrb_get_args(mrb, "o", &key);
const char *argv[] = {"HKEYS", RSTRING_PTR(key)};
size_t lens[] = {5, RSTRING_LEN(key)};
redisReply *rr = redisCommandArgv(rc, 2, argv, lens);
if (rr->type == REDIS_REPLY_ARRAY) {
if (rr->elements > 0) {
int i;
array = mrb_ary_new(mrb);
for (i = 0; i < rr->elements; i++) {
mrb_ary_push(mrb, array, mrb_str_new(mrb, rr->element[i]->str, rr->element[i]->len));
}
}
}
freeReplyObject(rr);
return array;
}
示例10: readHandler
static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
client c = privdata;
void *reply = NULL;
REDIS_NOTUSED(el);
REDIS_NOTUSED(fd);
REDIS_NOTUSED(mask);
/* Calculate latency only for the first read event. This means that the
* server already sent the reply and we need to parse it. Parsing overhead
* is not part of the latency, so calculate it only once, here. */
if (c->latency < 0) c->latency = ustime()-(c->start);
if (redisBufferRead(c->context) != REDIS_OK) {
fprintf(stderr,"Error: %s\n",c->context->errstr);
exit(1);
} else {
while(c->pending) {
if (redisGetReply(c->context,&reply) != REDIS_OK) {
fprintf(stderr,"Error: %s\n",c->context->errstr);
exit(1);
}
if (reply != NULL) {
if (reply == (void*)REDIS_REPLY_ERROR) {
fprintf(stderr,"Unexpected error reply, exiting...\n");
exit(1);
}
freeReplyObject(reply);
if (config.requests_finished < config.requests)
config.latency[config.requests_finished++] = c->latency;
c->pending--;
if (c->pending == 0) clientDone(c);
} else {
break;
}
}
}
}
示例11: keys
void keys(const char *pattern)
{
int i;
redisReply *reply;
reply = redisCommand(ctx, "KEYS %s", pattern);
if (reply == NULL)
{
log_error("keys fails: %s", ctx->errstr);
// handle error
return;
}
if (reply->type == REDIS_REPLY_ARRAY) {
for (i = 0; i < reply->elements; i++) {
log_debugv("%d) %s", i, reply->element[i]->str);
}
}
else {
log_warn("keys: unexpected reply type: %d", reply->type);
}
freeReplyObject(reply);
}
示例12: set_int_ex_nx
void set_int_ex_nx(const char *key, int val, int timeout)
{
redisReply *reply;
reply = redisCommand(ctx, "SET %s %d EX %d NX", key, val, timeout);
if (reply == NULL)
{
log_error("set_int_ex_nx fails: %s", ctx->errstr);
// handle error
return;
}
if (reply->type == REDIS_REPLY_STATUS) {
log_debugv("set_int_ex_nx %s %d %s", key, val, reply->str);
}
else if (reply->type == REDIS_REPLY_NIL) {
log_debugv("set_int_ex_nx: %s exists", key);
}
else {
log_warn("set_int_ex_nx: unexpected reply type: %d", reply->type);
}
freeReplyObject(reply);
}
示例13: add_one
int add_one(pyrebloomctxt *ctxt, const char *data, uint32_t data_size)
{
uint32_t ct = 0, total = 0, count = 1;
redisReply *reply = NULL;
for (uint32_t i = 0; i < ctxt->hashes; ++i) {
uint64_t hashed_data = hash(data, data_size, ctxt->seeds[i], ctxt->bits);
redisAppendCommand(ctxt->ctxt, "SETBIT %s %lu 1",
ctxt->keys[hashed_data / max_bits_per_key], hashed_data % max_bits_per_key);
}
for (uint32_t i = 0, ct = 0; i < ctxt->hashes; ++i) {
/* Make sure that we were able to read a reply. Otherwise, provide
* an error response */
if (redisGetReply(ctxt->ctxt, (void**)(&reply)) == REDIS_ERR) {
strncpy(ctxt->ctxt->errstr, "No pending replies", errstr_size);
ctxt->ctxt->err = PYREBLOOM_ERROR;
return PYREBLOOM_ERROR;
}
/* Consume and read the response */
if (reply->type == REDIS_REPLY_ERROR) {
ctxt->ctxt->err = PYREBLOOM_ERROR;
strncpy(ctxt->ctxt->errstr, reply->str, errstr_size);
} else {
ct += reply->integer;
}
freeReplyObject(reply);
}
if (ct == ctxt->hashes) {
total = 1;
}
if (ctxt->ctxt->err == PYREBLOOM_ERROR) {
return PYREBLOOM_ERROR;
}
return count - total;
}
示例14: hiredis_odb_backend__exists
int hiredis_odb_backend__exists(git_odb_backend *_backend, const git_oid *oid)
{
hiredis_odb_backend *backend;
int found;
redisReply *reply;
char *str_id = calloc(GIT_OID_HEXSZ + 1, sizeof(char));
assert(_backend && oid);
backend = (hiredis_odb_backend *) _backend;
found = 0;
git_oid_tostr(str_id, GIT_OID_HEXSZ, oid);
reply = redisCommand(backend->db, "exists %s:%s:odb:%s", backend->prefix, backend->repo_path, str_id);
if (reply->type == REDIS_REPLY_INTEGER)
found = reply->integer;
free(str_id);
freeReplyObject(reply);
return found;
}
示例15: ReConnect
bool Redis::Delete(string &key)
{
redisReply* reply = NULL;
log4cpp::Category& _logger = log4cpp::Category::getInstance("MAIN_LOG");
reply = (redisReply*)redisCommand(connect_, "del %s", key.c_str());
if (!reply){
ReConnect();
reply = (redisReply*)redisCommand(connect_, "del %s", key.c_str());
if (!reply){
_logger.error("delete key %s from redis error", key.c_str());
return RESULT_ERROR;
}
}
_logger.info("delete key %s from redis OK", key.c_str());
freeReplyObject(reply);
return RESULT_OK;
}