• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ redisConnect函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: redisConnect

bool RedisManager::connect()
{
  pubContext = redisConnect(config->host, config->port);
  if (pubContext != NULL && pubContext->err)
  {
    printf("%d\n", pubContext->err);
    return false;
  }

  subContext = redisConnect(config->host, config->port);
  if (subContext != NULL && subContext->err)
  {
    printf("%d\n", subContext->err);
    return false;
  }

  successContext = redisConnect(config->host, config->port);
  if(successContext != NULL && successContext->err)
  {
	  printf("%d\n", successContext->err);
	  return false;
  }
  redisCommand(successContext, "set successCount 0");

  totalContext = redisConnect(config->host, config->port);
  if(totalContext != NULL && totalContext->err)
  {
	  printf("%d\n", totalContext->err);
	  return false;
  }
  redisCommand(totalContext, "set totalCount 0");
  return true;
}
开发者ID:xiaoxiaozhao,项目名称:GeneralParser,代码行数:33,代码来源:redisManager.cpp


示例2: redis_dd_connect

static gboolean
redis_dd_connect(RedisDriver *self, gboolean reconnect)
{
  if (reconnect && (self->c != NULL))
    {
      redisCommand(self->c, "ping");

      if (!self->c->err)
        return TRUE;
      else
        self->c = redisConnect(self->host, self->port);
    }
  else
    self->c = redisConnect(self->host, self->port);

  if (self->c->err)
    {
      msg_error("REDIS server error, suspending",
                evt_tag_str("driver", self->super.super.super.id),
                evt_tag_str("error", self->c->errstr),
                evt_tag_int("time_reopen", self->super.time_reopen),
                NULL);
      return FALSE;
    }
  else
    msg_debug("Connecting to REDIS succeeded",
              evt_tag_str("driver", self->super.super.super.id), NULL);

  return TRUE;
}
开发者ID:algernon,项目名称:syslog-ng-old,代码行数:30,代码来源:redis.c


示例3: redisPoolInit

int redisPoolInit(redisPool *pool, char hostname[255], int poolsize)  {

    int i, fd;
    char currentdb[2];
    redisReply *reply;

    pool->size = poolsize;
    reply = redisConnect(&fd, hostname, cfg.redis_port);

    if(reply != NULL) {
        return -1;
    }

    reply = redisCommand(fd, "GET CURRENTDB");

    if(reply->type == REDIS_REPLY_STRING) {
        snprintf(currentdb, strlen(reply->reply) +1, "%s", reply->reply);
    }

    if(atoi(currentdb) == 0) {
        printf("Current db not configured\n");
        syslog(LOG_ERR, "Current db not configured");
        return -1;
    }
        
    syslog(LOG_INFO, "Current database selected: %s", reply->reply);

    freeReplyObject(reply);
    close(fd);

    for(i = 0; i < poolsize; i++) {
        if(pool->fd[i])
           close(pool->fd[i]);

        reply = redisConnect(&pool->fd[i], hostname, cfg.redis_port);
        if(reply != NULL) {
            freeReplyObject(reply);
            return -1;
        }
    
        reply = redisCommand(pool->fd[i], "SELECT %s", currentdb);
        freeReplyObject(reply);
    }

    if(cfg.expire_seconds == 0) {
        reply = redisCommand(pool->fd[0], "KEYS *");
        if(reply->type == REDIS_REPLY_ARRAY)  {
            if(reply->elements == 0 ) {
                printf("Empty database, i'm fuc**ng off\n");
                syslog(LOG_ERR, "Empty database, i'm fuc**ng off");
                freeReplyObject(reply);
                return -1;
            }
        }
        freeReplyObject(reply);
    }
    pool->current = 0;
    return 0;
}
开发者ID:samgaw,项目名称:Postfix-Redis-TCP-Map,代码行数:59,代码来源:redis.c


示例4: main

int main(void) {
    int ppid = fork();
    if (ppid == 0) {
        redisContext *c;
        redisReply *reply;
        c = redisConnect((char*)"127.0.0.1", 6379);
        if (c->err) {
            printf("Connection error: %s\n", c->errstr);
            exit(1);
        }
        
        printf("Subscribing\n");
        reply = redisCommand(c,"SUBSCRIBE foo");
        freeReplyObject(reply);
        
        // Should get bar
        redisGetReply(c, (void**)&reply);
        printf("Reply is: %s\n", reply->element[2]->str);
        freeReplyObject(reply);
        
        printf("Unsubscribing\n");
        reply = redisCommand(c,"PUNSUBSCRIBE *");
        printf("Unsubscribed from %s\n", reply->element[1]->str);
        freeReplyObject(reply);
        
        // Really, we should hang here, but we'll get zip
        redisGetReply(c, (void**)&reply);
        printf("Reply is: %s\n", reply->element[2]->str);
        freeReplyObject(reply);
        exit(0);
    }
    else {
        redisContext *c;
        redisReply *reply;
        c = redisConnect((char*)"127.0.0.1", 6379);
        if (c->err) {
            printf("Connection error: %s\n", c->errstr);
            exit(1);
        }
        
        // I expect this to go through
        sleep(1);
        printf("Publishing");
        reply = redisCommand(c, "PUBLISH foo bar");
        freeReplyObject(reply);
        
        // This should come in after the unsubscribe (monitor can confirm this)
        sleep(1);
        printf("Publishing");
        reply = redisCommand(c, "PUBLISH foo zip");
        freeReplyObject(reply);
    }
    wait(0);
    return 0;
}
开发者ID:haseok86,项目名称:millkencode,代码行数:55,代码来源:pubsubtest.c


示例5: cliConnect

/* Connect to the client. If force is not zero the connection is performed
 * even if there is already a connected socket. */
static int cliConnect(int force) {
    if (context == NULL || force) {
        if (context != NULL)
            redisFree(context);

        if (config.hostsocket == NULL) {
            context = redisConnect(config.hostip,config.hostport);
        } else {
            context = redisConnectUnix(config.hostsocket);
        }

        if (context->err) {
            fprintf(stderr,"Could not connect to Redis at ");
            if (config.hostsocket == NULL)
                fprintf(stderr,"%s:%d: %s\n",config.hostip,config.hostport,context->errstr);
            else
                fprintf(stderr,"%s: %s\n",config.hostsocket,context->errstr);
            redisFree(context);
            context = NULL;
            return REDIS_ERR;
        }

        /* Do AUTH and select the right DB. */
        if (cliAuth() != REDIS_OK)
            return REDIS_ERR;
        if (cliSelect() != REDIS_OK)
            return REDIS_ERR;
    }
    return REDIS_OK;
}
开发者ID:CNCBASHER,项目名称:linuxcnc-1,代码行数:32,代码来源:redis-cli.c


示例6: main

int main(int argc, char *argv[]) {
  redisReply *reply;
  int deleted_keys_count = 0;

  if (argc < 2) {
    printf("Usage: redis-checksum directory [--dry-run]\n");
    return 1;
  }

  if (argc > 2 && (strcmp(argv[2], "--dry-run") == 0)) {
    dry_run = 1;
  }


  redis = redisConnect("127.0.0.1", 6379);

  if(redis->err) {
    fprintf(stderr, "Connection error: %s\n", redis->errstr);
    exit(EXIT_FAILURE);
  }

  // Get rid of non-existent files from redis
  remove_stale_redis_keys(redis);

  ftw(argv[1], &redis_upsert_file, 10);

  printf("Summary%s:\n", (dry_run) ? " (DRY RUN)" : "");
  printf("Keys Added:   %d\n", counts[REDIS_COUNT_ADDED]);
  printf("Keys Updated: %d\n", counts[REDIS_COUNT_UPDATED]);
  printf("Keys Deleted: %d\n", counts[REDIS_COUNT_DELETED]);

  return 0;
}
开发者ID:danlamanna,项目名称:redis-mlocate-database,代码行数:33,代码来源:main.c


示例7: save_img_db

/**
 * @brief save_img_db Choose db mode to save images.
 *
 * @param thr_arg Thread arg struct.
 * @param cache_key The key of image.
 * @param buff Image buffer.
 * @param len Image size.
 *
 * @return 1 for succ or -1 for fialed.
 */
int save_img_db(thr_arg_t *thr_arg, const char *cache_key, const char *buff, const size_t len)
{
    int ret = -1;
    if(settings.mode == 2)
        ret = save_img_beansdb(thr_arg->beansdb_conn, cache_key, buff, len);
    else if(settings.mode == 3)
        ret = save_img_ssdb(thr_arg->ssdb_conn, cache_key, buff, len);

    if(ret == -1 && settings.mode == 3)
    {
        if(thr_arg->ssdb_conn != NULL)
            redisFree(thr_arg->ssdb_conn);
        redisContext* c = redisConnect(settings.ssdb_ip, settings.ssdb_port);
        if(c->err)
        {
            redisFree(c);
            LOG_PRINT(LOG_DEBUG, "Connect to ssdb server faile");
            return ret;
        }
        else
        {
            thr_arg->ssdb_conn = c;
            LOG_PRINT(LOG_DEBUG, "SSDB Server Reconnected.");
            ret = save_img_ssdb(thr_arg->ssdb_conn, cache_key, buff, len);
            //evthr_set_aux(thr_arg->thread, thr_arg);
        }
    }
    return ret;
}
开发者ID:haython,项目名称:zimg,代码行数:39,代码来源:zdb.c


示例8: redisConnect

redisContext *_myredisConnect(struct config config) {
    redisContext *c = NULL;
    redisReply *reply;
    char cmd[256];
    int len;

   if (config.type == CONN_TCP) {
        c = redisConnect(config.tcp.host, config.tcp.port);
    } else if (config.type == CONN_UNIX_SOCK) {
        c = redisConnectUnix(config.unix_sock.path);
    } else {
        assert(NULL);
    }

    if (c->err && pFile) {
    	info_print("Connection error: %s\n", c->errstr);
	return c;
    }


    /* Authenticate */
    if (config.auth) {
        reply = redisCommand(c,"AUTH %s",config.password);
        if(reply) {
            freeReplyObject(reply);
	}
    }
    return c;
}
开发者ID:AALEKH,项目名称:mysql2redis,代码行数:29,代码来源:lib_mysqludf_redis.c


示例9: redisConnect

bool CRedisUtil::Connect(const char* pszAddr, int nPort, int nDbId)
{
	m_redis = redisConnect(pszAddr, nPort);
	if (m_redis->err != 0)
	{
		LogError("redis_connect", "failed to connect: %s:%d ,err=%s", pszAddr, nPort, m_redis->errstr);
		return false;
	}
	//选择库
	char szCommond[24];
	memset(szCommond, 0, sizeof(szCommond));
	snprintf(szCommond, sizeof(szCommond), "SELECT %d", nDbId);
	redisReply* reply = (redisReply*)redisCommand(m_redis, szCommond);
	if (!reply)
	{
		LogError("redis_connect", szCommond);
		return false;
	}
	else
	{
		LogInfo("redis_connect", szCommond);
		//LogDebug("freeReplyObject", "%s : %d", __FILE__, __LINE__);
		freeReplyObject(reply);
	}
	return true;
}
开发者ID:ilvxna,项目名称:ahzs_easy,代码行数:26,代码来源:myredis.cpp


示例10: send_commands

int send_commands(std::vector<std::string> cmds, std::vector<std::string> times, Json::Value &json_data) {
	redisContext *rc = redisConnect("localhost", 6379);

	for(size_t i=0;i<cmds.size();i++) {
		redisAppendCommand(rc, cmds[i].c_str());
	}

	for(size_t i=0;i<cmds.size();i++) {
		redisReply *reply;
		redisGetReply(rc, (void **)&reply);

		if(reply->type == REDIS_REPLY_ERROR) {
			LOG_WARN("redis return error which msg:%s", reply->str);
			continue;
		}
		int pv_value = reply->type == REDIS_REPLY_NIL ? 0 : atoi(reply->str);

		Json::ArrayIndex index = (Json::ArrayIndex) i;
		json_data[index]["unit"] = times[i];
		json_data[index]["value"] = pv_value;
		LOG_DEBUG("start_time:%s, pv:%d", times[i].c_str(), pv_value);

		if(reply != NULL) {
			freeReplyObject(reply);
		}
	}

	redisFree(rc);
	return 0;
}
开发者ID:mushanzi1216,项目名称:simple_flow,代码行数:30,代码来源:statistic_http_server.cpp


示例11: strcpy

statistics_t *statistics_open(const char *path, const database_t *redis)
{
    /* allocate memory. */
    statistics_t *stats = (statistics_t *)malloc(sizeof(statistics_t));
    strcpy(stats->fname, path);

    /* open statistics file. */
    stats->fd = open(path, O_CREAT | O_RDWR | O_APPEND, S_IRUSR | S_IWUSR);
    if (stats->fd == -1) {
        log_error("open statistics file [%s] error, errno [%d]", path, errno);
        return NULL;
    }

    stats->conn = redisConnect(redis->ip, redis->port);
    if (stats->conn == NULL || stats->conn->err) {
        if (stats->conn != NULL) {
            log_error("Connection error: %s", stats->conn->errstr);
        } else {
            log_error("Connection error: can't allocate statistics redis context");
        }
        return NULL;
    }

    return stats;
}
开发者ID:swordflychen,项目名称:TSDB_CLUSTER,代码行数:25,代码来源:statistics.c


示例12: redisConnect

void *Redis_create(char *host, int port) {
	redisContext *con;
	con = redisConnect(host, port);

	if (con == NULL || con->err) {
		if (con) {
			printf("Connection error: %s\n", con->errstr);
			redisFree(con);
		} else {
			printf("Connection error: can't allocate redis context\n");
		}
		exit(1);
	}

	Redis proto = { .host = host, .port = port, .con = con, .init = Redis_init,
			.readReply = Redis_readReply, .close = Redis_close, .command =
					Redis_command };

	Redis *m = calloc(1, sizeof(Redis));
	*m = proto;

	if (!m->init(m)) {
		// looks like it didn't initialize properly
		m->close(m);
		return NULL;
	} else {
		// all done, we made an object of any type
		return m;
	}

}
开发者ID:vincentlooi,项目名称:C_stuff,代码行数:31,代码来源:redisStuff.c


示例13: _nss_redis_redis_connect

redisContext*
_nss_redis_redis_connect() {

  if (c)  {
    return c;
  }

  if(*_nss_redis_config.host == '/') {
    c = redisConnectUnix(_nss_redis_config.host);
  } else{
    c = redisConnect(_nss_redis_config.host, _nss_redis_config.port);
  }

  if(c->err) {
    redisFree(c);
    c = NULL;
    goto connected;
  }

  if(_nss_redis_redis_auth(c) == false) {
    c = NULL;
    goto connected;
  }

 connected:
  return c;
}
开发者ID:hiboma,项目名称:nss_redis,代码行数:27,代码来源:nss_redis_utils.c


示例14: emit_init

int emit_init()
{
    char *host, *buf = strdup(config.emit_option), *bp;
    int port;

    if ((bp = strchr(buf, '/')) == NULL) {
    	fprintf(stderr, "Redis emitter option is bad (no slash)\n");
	return (1);
    }
    *bp = 0;
    port = atoi(bp+1);
    host = buf;

    config.rediscon = redisConnect(host, port);
    if (config.rediscon->err) {
    	fprintf(stderr, "Cannot connect to Redis at %s:%d: %s\n",
		host, port, config.rediscon->errstr);
	return (1);
    }

    olog("[*] Connected to Redis at %s:%d with nsid=%s (topic=%s)\n\n",
    	host, port, config.nsid, config.emit_topic);

    free(buf);
    return (0);
}
开发者ID:DavidPratama,项目名称:stash53,代码行数:26,代码来源:emit.c


示例15: post_config

/* Set up startup-time initialization */
static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
    void *data;
    const char *userdata_key = "llzr_init";
    llzr_config *conf = ap_get_module_config(parms->server->module_config, &llzr_module);

    conf->redisconn = redisConnect(conf->redis_host, conf->redis_port);
    if (conf->redisconn == NULL || conf->redisconn->err) {
        if (conf->redisconn) {
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "Redis error encountered %s", conf->redisconn->errstr);
            redisFree(c);
        } else {
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "Unable to connect to redis server");
        }

        /* We don't want to kill our site if Redis goes down, but we would be susceptible to attack */
    }

    apr_pool_userdata_get(&data, userdata_key, s->process->pool);
    if (!data) {
	   apr_pool_userdata_set((const void *)1, userdata_key,apr_pool_cleanup_null, s->process->pool);
	       return OK;
    }

    /* Lets get details from the MPM */
    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, MODULE_NAME " " MODULE_VERSION " started");
    ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
    ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);

    return OK;
}
开发者ID:mikemackintosh,项目名称:Apache-LoginLimitizer,代码行数:32,代码来源:mod_llzr.c


示例16: oidc_cache_redis_connect

/*
 * connect to Redis server
 */
static redisContext * oidc_cache_redis_connect(request_rec *r,
		oidc_cache_cfg_redis_t *context) {

	/* see if we already have a connection by looking it up in the process context */
	redisContext *ctx = NULL;
	apr_pool_userdata_get((void **) &ctx, OIDC_CACHE_REDIS_CONTEXT,
			r->server->process->pool);

	if (ctx == NULL) {

		/* no connection, connect to the configured Redis server */
		ctx = redisConnect(context->host_str, context->port);

		/* check for errors */
		if ((ctx == NULL) || (ctx->err != 0)) {
			oidc_error(r, "failed to connect to Redis server (%s:%d): '%s'",
					context->host_str, context->port, ctx->errstr);
			return NULL;
		}

		/* store the connection in the process context */
		apr_pool_userdata_set(ctx, OIDC_CACHE_REDIS_CONTEXT,
				(apr_status_t (*)(void *)) redisFree, r->server->process->pool);

		/* log the connection */
		oidc_debug(r, "successfully connected to Redis server (%s:%d)",
				context->host_str, context->port);
	}

	return ctx;
}
开发者ID:Acidburn0zzz,项目名称:mod_auth_openidc,代码行数:34,代码来源:redis.c


示例17: git_odb_backend_hiredis

int git_odb_backend_hiredis(git_odb_backend **backend_out, const char *host, int port)
{
    hiredis_backend *backend;

    backend = calloc(1, sizeof (hiredis_backend));
    if (backend == NULL)
        return GITERR_NOMEMORY;

    backend->db = redisConnect(host, port);
    if (backend->db->err) {
		free(backend);
		return GIT_ERROR;
	}

    backend->parent.read = &hiredis_backend__read;
    backend->parent.read_prefix = &hiredis_backend__read_prefix;
    backend->parent.read_header = &hiredis_backend__read_header;
    backend->parent.write = &hiredis_backend__write;
    backend->parent.exists = &hiredis_backend__exists;
    backend->parent.free = &hiredis_backend__free;

    *backend_out = (git_odb_backend *) backend;

    return GIT_OK;
}
开发者ID:nathancahill,项目名称:libgit2-backends,代码行数:25,代码来源:hiredis.c


示例18: write_redis

void write_redis(const char * key, char *value, int len) {
	const char * ip = "127.0.0.1";
	int port = 6379;
	int dbno = 1;
	redisContext *con = redisConnect(ip, port);
	if (con->err) {
		redisFree(con);
		printf("Connection error: %s", con->errstr);
		exit(-1);
	}

	printf("Writing...");
	time_t start, end;
	start = clock();

	void *reply0 = redisCommand(con, "select %d", dbno);
	void *reply1 = redisCommand(con, "SET key:%s %b", key, value,
			len * sizeof(char));

	end = clock();
	printf("%f seconds.\n", (double) (end - start) / CLOCKS_PER_SEC);

	freeReplyObject(reply0);
	freeReplyObject(reply1);
	redisFree(con);
}
开发者ID:lulyon,项目名称:RedisBasicIOTest,代码行数:26,代码来源:databaseTest.cpp


示例19: redis

int redis()
{
	char * insert_command;
	redisContext baglam;
	baglam = redisConnect("127.0.0.1", 6379);
	if (baglam == NULL)
	{
		printf("Baglanamadi!");
	}
	else
	{
		printf("Baglandi!");

	}
/*	insert_command = malloc(sizeof(1024));
	sprintf(insert_command,
			"INSERT INTO \"NODE-software\" VALUES (%s, '%s', '%s', '%s', '%s', '%s', \
			'%s', '%s','%s', '%s', %d, \
			'%s', '%s','%s', '%s','%s', '%s', \
			'%s', '%s', '%s', '%s');" \
			,ms4db_ptr->resourceType ,ms4db_ptr->name, m2mSmGenerateRandomId(BIG_SIZE), (char *)ms4db_ptr->creationTime, (char *)ms4db_ptr->lastModifiedTime, "",\
			"", (char *)ms4db_ptr->expirationTime,"", "", ms4db_ptr->mgmtDefinition, \
			ms4db_ptr->name, "/opt/m2m/update/", "", ms4db_ptr->version, ms4db_ptr->name, ms4db_ptr->url, \
		    ms4db_ptr->install?"true":"false", ms4db_ptr->uninstall?"true":"false", ms4db_ptr->activate?"true":"false", ms4db_ptr->deactivate?"true":"false");

	resultPtr = execCommand(conPtr, insert_command);
	DEBUG("Command: %s", insert_command);

	if(resultPtr != NULL)
	{
		free(resultPtr);
	}*/
	return 1;
}
开发者ID:Cybermilitia,项目名称:HiredisOnRamFile,代码行数:34,代码来源:RamFile.c


示例20: redisConnect

MHIREDIS_T MHiRedis::connect(const std::string& host, const int port,
                             const std::sting& password, const int db) {
    context_ = redisConnect(host_ip_.c_str(), port_);

    if (!context_) {
        cleanUp();
        return MH_CONNECT_RET_NULL;
    }

    if (context_->err != 0) {
        // log errstr

        cleanUp();
        return MH_CONNECT_ERROR;
    }
    if (!passwork.emply()) {
        std::string auth_comm = "AUTH " + password;
        MHIREDIS_T ret = execCommand(auth_comm, NULL);
        if (ret != MH_SUCCESS) {
            return MH_AUTH_FAILED;
        }
    }

    std::string sel_comm = "SELECT " + itoa(db);
    ret = execCommand(sel_comm, NULL);
    if (ret != MH_SUCCESS) {
        return MH_SEL_FAILED;
    }

    return MH_SUCCESS;
}
开发者ID:dcj227,项目名称:cpp_code,代码行数:31,代码来源:multi_thread_redis_access.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ redisConnectWithTimeout函数代码示例发布时间:2022-05-30
下一篇:
C++ redisCommand函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap