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

C++ redisConnectWithTimeout函数代码示例

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

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



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

示例1: init_pyrebloom

int init_pyrebloom(pyrebloomctxt * ctxt, unsigned char * key, uint32_t capacity, double error, char* host, uint32_t port) {
  // Counter
  uint32_t i;

  ctxt->capacity = capacity;
  ctxt->bits     = - (uint32_t)((log(error) * capacity) / (log(2) * log(2)));
  ctxt->hashes   = (uint32_t)(ceil(log(2) * ctxt->bits / capacity));
  ctxt->error    = error;
  ctxt->key      = key;//(unsigned char *)(malloc(strlen(key)));
  //strcpy(ctxt->key, key);
  ctxt->seeds    = (uint32_t *)(malloc(ctxt->hashes * sizeof(uint32_t)));
  // Generate all the seeds
  // Make sure we get the same seeds on subsequent calls.
  srand(0);
  for (i = 0; i < ctxt->hashes; ++i) {
    ctxt->seeds[i] = (uint32_t)(rand());
  }

  // Now for the redis context
  struct timeval timeout = { 1, 500000 };
  ctxt->ctxt     = redisConnectWithTimeout(host, port, timeout);
  if (ctxt->ctxt->err) {
    // Some kind of error
    return 0;
  }
  return 1;
}
开发者ID:hazzadous,项目名称:pyreBloom,代码行数:27,代码来源:bloom.c


示例2: main

int main(int argc, char** argv)
{
    redisReply* reply;
    redisReply* reply1;
    redisReply* reply2;
    redisReply* reply3;
    struct timeval timeout = {1, 0};
    char* meta_ip;
    unsigned short meta_port;
    char command[1024];

    if (argc < 3) {
        fprintf(stderr, "Right usage: meta_tool meta_ip meta_port");
        return -1;
    }
    meta_ip = argv[1];
    meta_port = (unsigned short)strtoul(argv[2], (char**)NULL, 10);
    // meta_ip = "10.209.52.30";
    // meta_port = 6000;

    context = redisConnectWithTimeout(meta_ip, meta_port, timeout);

    if (context == NULL) {
        FATAL("connect to meta server failed");
        freeReplyObject(reply);
	return -1;
    }

    if (context->err) {
        FATAL("connect to meta failed: %s", context->errstr);
        freeReplyObject(reply);
	return -1;
    }

    reply = (redisReply*)redisCommand(context, "hgetall bae_apps_hash");
    if (reply == NULL) {
        FATAL("hgetall bae_apps_hash failed: %s", context->errstr);
        freeReplyObject(reply);
	return -1;
    } else if (reply->type != REDIS_REPLY_ARRAY) {
        FATAL("invalid reply type:%d, REDIS_REPLY_ARRAY %u\n",
		reply->type, REDIS_REPLY_ARRAY);
        freeReplyObject(reply);
	return -1;
    }
    for (unsigned idx = 0; idx < reply->elements; idx += 2) {
        reply1 = reply->element[idx];
        reply2 = reply->element[idx + 1];
        //printf("%s:%s\n", reply1->str, reply2->str);
        sprintf(command, "hdel bae_apps_hash %s", reply1->str);
        reply3 = (redisReply*)redisCommand(context, command);
        freeReplyObject(reply3);
        parseAppsHash(reply2->str);
    }

    freeReplyObject(reply);
    redisFree(context);

    return 0;
}
开发者ID:bugou,项目名称:test,代码行数:60,代码来源:appid2UserId.c


示例3: redisConnectWithTimeout

int     ConfigCenter::Init(const char* pszHostName ,int port,int dbidx ,int timeout )
{
    m_ctx = NULL;
    m_reply = NULL;
    /////////////////////////////////
    struct timeval tvout = { timeout/1000, (timeout%1000)*1000 };
    m_ctx = redisConnectWithTimeout(pszHostName, port, tvout);
    if (m_ctx == NULL || m_ctx->err) 
    {
        if (m_ctx) 
        {
            LOG_ERROR("redis Connection error: %s\n", m_ctx->errstr);
            redisFree(m_ctx);
        }
        else
        {
            LOG_ERROR("redis Connection error: can't allocate redis context\n");
        }
        return -1;
    }    
    m_reply = (redisReply*)redisCommand(m_ctx,"SELECT %d",dbidx);
    freeReplyObject(m_reply);
    LOG_INFO("config center init ok !");
    return HeartBeat();
}
开发者ID:jj4jj,项目名称:playground,代码行数:25,代码来源:ConfigCenter.cpp


示例4: Quit

bool RedisClient::Connect()
{
	if (IsConnected())
	{
		Quit();
	}
	if (m_strName.IsEmpty()) return false;
	struct timeval timeout = { 5, 500000 }; // 1.5 seconds 
	m_pClient = redisConnectWithTimeout((char*)m_strIP.c_str(), 
		m_iPort, 
		timeout);
	if (m_pClient->err) {
		printf("Connection error: %s\n", m_pClient->errstr);
		SetLastError(m_pClient->errstr);
		return false;
	}
	if (!m_strAuth.empty())
	{
		redisReply* reply = Command("AUTH %s", m_strAuth.c_str());
		if (!(reply && reply->type==REDIS_REPLY_STATUS))
		{
			return false;
		}
	}
	m_isConnected = true;
	if (m_isConnected && DatabasesNum(m_Databases)) return true;
	return false;
}
开发者ID:aharrya,项目名称:RedisStudio,代码行数:28,代码来源:RedisClient.cpp


示例5: redisConnectWithTimeout

//redis,add,begin
bool QTSServerInterface::ConRedis()//连接redis服务器
{
	if(fIfConSucess)
		return true;

	struct timeval timeout = { 0, 500000 }; // 0.5 seconds
	fRedisCon = redisConnectWithTimeout(fRedisIP.c_str(), fRedisPort, timeout);//test,redis的ip和端口应该在xml中指定
	if (fRedisCon == NULL || fRedisCon->err)
	{
		if (fRedisCon) {
			qtss_printf("INFO:Connect redis failed,%s\n", fRedisCon->errstr);
			redisFree(fRedisCon);
		} else {
			qtss_printf("INFO:Connect redis failed,can't allocate redis context\n");
		}
		fIfConSucess=false;
	}
	else
	{
		fIfConSucess=true;
		struct timeval timeoutEx = { 1, 0 }; // 1seconds,设置socket接收和发送超时
		redisSetTimeout(fRedisCon,timeoutEx);

		RedisInit();//可能在这个函数的执行过程中,redis连接又失败了,所以真正的连接失败或者成功要看fIfConSucess
		qtss_printf("INFO:Connect redis sucess\n");
	}
	return fIfConSucess;
}
开发者ID:ihitao,项目名称:EasyDarwin,代码行数:29,代码来源:QTSServerInterface.cpp


示例6: LM_INFO

static struct redis *__redis_connect(struct redis *redis)
{
	struct timeval timeout = {1, 500000}; // 1.5 seconds

	LM_INFO("Connecting to Redis at %s:%d\n", redis->ip, redis->port);

	if(redis->ctxt)
		redisFree(redis->ctxt);

	redis->ctxt = redisConnectWithTimeout(redis->ip, redis->port, timeout);

	if(redis->ctxt == NULL || redis->ctxt->err) {
		if(!redis->ctxt)
			LM_ERR("Connection error: can't allocate Redis context\n");
		else {
			LM_ERR("Connection error: %s\n", redis->ctxt->errstr);
			redisFree(redis->ctxt);
		}

		return NULL;
	}

	if(!__redis_select_db(redis->ctxt, redis->db))
		return NULL;

	return redis;
}
开发者ID:adubovikov,项目名称:kamailio,代码行数:27,代码来源:cnxcc_redis.c


示例7: redisConnectWithTimeout

static redisContext *init_redisclient(server_rec *s, const char *redis_ip, int redis_port, const char *redis_password)
{

    redisContext *ctx;
    redisReply *reply;
    struct timeval timeout = { 1, 500000 }; // 1.5 seconds

    ctx = redisConnectWithTimeout(redis_ip, redis_port, timeout);
    if (ctx == NULL || ctx->err) {

        if (ctx) {
            free_redis_ctx(ctx, s);
        } 
    	ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "redis connection fail.");
        return NULL;
    }

    // AUTH 
    reply = redisCommand(ctx,"AUTH %s", redis_password);
    if (reply == NULL) {
        // wrong redis password
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,"wrong redis password");
        free_redis_ctx(ctx, s);
        return NULL;
    }
    // DEBUG
    //ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,"redis reply: AUTH, type[%d], str[%s]", reply->type, reply->str);
    freeReplyObject(reply);

    return ctx;
}
开发者ID:han507,项目名称:secuip,代码行数:31,代码来源:mod_secuip.c


示例8: rc_validate_connection

static void rc_validate_connection(rconn_t *c, int optional) {
    if (!c->rc && (c->flags & RCF_RECONNECT)) {
	struct timeval tv;
	tv.tv_sec = (int) c->timeout;
	tv.tv_usec = (c->timeout - (double)tv.tv_sec) * 1000000.0;
	if (c->port < 1)
	    c->rc = redisConnectUnixWithTimeout(c->host, tv);
	else
	    c->rc = redisConnectWithTimeout(c->host, c->port, tv);
	if (!c->rc) {
	    if (optional) return;
	    Rf_error("disconnected connection and re-connect to redis failed (NULL context)");
	}
	if (c->rc->err){
	    SEXP es = Rf_mkChar(c->rc->errstr);
	    redisFree(c->rc);
	    c->rc = 0;
	    if (optional) return;
	    Rf_error("disconnected connection and re-connect to redis failed: %s", CHAR(es));
	}
	redisSetTimeout(c->rc, tv);
	/* re-connect succeeded */
    }
    if (!c->rc && !optional)
	Rf_error("disconnected redis connection");
}
开发者ID:nandakishorkoka,项目名称:rediscc,代码行数:26,代码来源:credis.c


示例9: get_redis_context

static redisContext*
get_redis_context(ngx_http_request_t *r)
{
  redisContext *context;
  repsheet_main_conf_t *conf;

  conf = ngx_http_get_module_main_conf(r, ngx_http_repsheet_module);

  struct timeval timeout = { 0, conf->redis.timeout };

  context = redisConnectWithTimeout((char*)conf->redis.host.data, conf->redis.port, timeout);

  if (context == NULL) {
    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "%s %s Connection Error: can't allocate redis context", "[repsheet]");
    return NULL;
  }

  if (context->err) {
    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "%s Redis Connection Error: %s", "[repsheet]", context->errstr);
    redisFree(context);
    return NULL;
  }

  return context;
}
开发者ID:ingoclaro,项目名称:repsheet,代码行数:25,代码来源:ngx_http_repsheet_module.c


示例10: redisConnectWithTimeout

redisContext* RedisConnPool::Connect()
{
    struct timeval tv;
    tv.tv_sec =  conn_timeout_ms_/1000;
    tv.tv_usec = (conn_timeout_ms_%1000)*1000;

    redisContext *c = redisConnectWithTimeout(host_.c_str(), port_, tv);
    if(c == NULL) {
        return NULL;
    }

    if(c->err) { 
        log_error("connect redis failed. ip=[%s] port=[%d],c->strerr=%s", 
                    host_.c_str(), port_, c->errstr);
        redisFree(c);
        c = NULL;
        return NULL;
    }

    struct timeval rtv;
    rtv.tv_sec =   recv_timeout_ms_/1000;
    rtv.tv_usec =  (recv_timeout_ms_%1000)*1000;
    redisSetTimeout(c, rtv);
    return c;
}
开发者ID:chenbaihu,项目名称:cpp_coding,代码行数:25,代码来源:RedisConnPool.cpp


示例11: redisConnectWithTimeout

int32_t ClusterRedis::Init() {
    struct timeval timeout = { 1, 500000}; // 1.5 seconds
    _redisContext = redisConnectWithTimeout(_redisIP, _redisPort, timeout);
    if (!_redisContext || _redisContext->err) {
        if (_redisContext) {
            logg(ERROR, "fail to connect redis, ip: %s, port: %d, errorInfo: %s",
                 _redisIP, _redisPort, _redisContext->errstr);
        } else {
            logg(ERROR, "fail to connect redis, ip: %s, port: %d",
                 _redisIP, _redisPort);
        }
        return -2;
    }

    //test, connect Redis-server
    //if (this->Connect_Ping()) return -3;
    if (!is_master_) {
        _redisReply = (redisReply *)redisCommand(_redisContext, "readonly");
        if (_redisReply) {
            if (_redisReply->type == REDIS_REPLY_STATUS
                    && !strcmp(_redisReply->str, "OK"))
            {
                logg(DEBUG, "set to readonly");
                readonly_ = true;
                return 0;
            }
        }
        return -2;
    }

    this->FreeSources();
    return 0;
}
开发者ID:ppLorins,项目名称:redis-cpp-cluster,代码行数:33,代码来源:Cluster_Redis.cpp


示例12: connect_to_redis

 redisContext* connect_to_redis() {
     redisContext* rc=NULL;
     struct timeval tv;
     tv.tv_sec=1000/1000;
     tv.tv_usec=1000*1000;
     rc=redisConnectWithTimeout(redis_host,redis_port,tv);
     return rc;
 }
开发者ID:easyfun,项目名称:my_projects,代码行数:8,代码来源:multi_test_redis.cpp


示例13: p4ns_db_connect

p4ns_db_cxt_t p4ns_db_connect(char *ipv4, uint16_t port) {
  struct timeval timeout = { DB_CONNECT_TIMEOUT_SECS, 0 };
  redisContext *c = redisConnectWithTimeout(ipv4, port, timeout);
  if (c == NULL || c->err) {
    return NULL;
  }
  return c;
}
开发者ID:25dedezembro,项目名称:p4factory,代码行数:8,代码来源:p4ns_db.c


示例14: init_redis_context

void init_redis_context(redisContext ** context,char * ip_port[])
{
	const char *hostname =ip_port[1]; 
    	int port = atoi(ip_port[2]);
    	struct timeval timeout = { 1, 500000 }; // 1.5 seconds
   	*context = redisConnectWithTimeout(hostname, port, timeout);

}
开发者ID:liyang1025,项目名称:syndata,代码行数:8,代码来源:syndata.c


示例15: redisInit

int redisInit( void )
{
    struct timeval timeout = { 1, 500000 }; // 1.5 seconds
    redisC = redisConnectWithTimeout((char*)"127.0.0.1", 6379, timeout);
    if (redisC->err) {
        printf("Connection error: %s\n", redisC->errstr);
        return 1;
    }
    return 0;
}
开发者ID:esromneb,项目名称:sjsu-cs267,代码行数:10,代码来源:redis-slave.c


示例16: flapjack_push

static int flapjack_push (char const *buffer, user_data_t *ud) /* {{{ */
{
  fj_node_t *node = ud->data;
  redisReply *rr;

  pthread_mutex_lock (&node->lock);

  if (node->conn == NULL)
  {
    node->conn = redisConnectWithTimeout ((char *)node->host, node->port, node->timeout);
    if (node->conn == NULL)
    {
      ERROR ("notify_flapjack plugin: Connecting to host \"%s\" (port %i) failed: Unkown reason",
          (node->host != NULL) ? node->host : "localhost",
          (node->port != 0) ? node->port : 6379);
      pthread_mutex_unlock (&node->lock);
      return (-1);
    }
    else if (node->conn->err)
    {
      ERROR ("notify_flapjack plugin: Connecting to host \"%s\" (port %i) failed: %s",
          (node->host != NULL) ? node->host : "localhost",
          (node->port != 0) ? node->port : 6379,
          node->conn->errstr);
      pthread_mutex_unlock (&node->lock);
      return (-1);
    }

    rr = redisCommand(node->conn, "SELECT %d", node->database);
    if (rr == NULL)
      WARNING("notify_flapjack plugin: %s:%d SELECT command error. database:%d message:%s", node->host, node->port, node->database, node->conn->errstr);
    else
      freeReplyObject (rr);
  }

  DEBUG("notify_flapjack plugin: %s:%d:%d LPUSH events %s", node->host, node->port, node->database, buffer);

  rr = redisCommand (node->conn, "LPUSH %s %s", "events", buffer);
  if (rr == NULL)
    WARNING("notify_flapjack plugin: %s:%d:%d LPUSH command error (events). message:%s", node->host, node->port, node->database, node->conn->errstr);
  else
    freeReplyObject (rr);

  if ( node->flapjack_version > 1) {
    rr = redisCommand (node->conn, "LPUSH events_actions +");
    if (rr == NULL)
      WARNING("notify_flapjack plugin: %s:%d:%d LPUSH command error (events_actions). message:%s", node->host, node->port, node->database, node->conn->errstr);
    else
      freeReplyObject (rr);
  }

  pthread_mutex_unlock (&node->lock);

  return (0);
} /* }}} int flpjack_push */
开发者ID:bs-github,项目名称:collectd,代码行数:55,代码来源:notify_flapjack.c


示例17: redisConnectWithTimeout

/**
 * Connects to redis service.  Asserts on failure.
 */
static redisContext *connect_to_redis() {
  redisContext *c = NULL;

  c = redisConnectWithTimeout(REDIS_IP, REDIS_PORT, g_timeout);
  if (c == NULL) {
    zlog_err("%s:, failed to connect to redis", __func__);
    assert(0);
  }

  return(c);
}
开发者ID:RS1999ent,项目名称:quagga_evolvabilty,代码行数:14,代码来源:dbgp_lookup.c


示例18: mc_connect

int mc_connect(mc_t *mc)
{
        struct timeval timeout = { 1, 500000 }; // 1.5 seconds
	mc->mc = redisConnectWithTimeout(mc->ip, atoi(mc->port), timeout);

        if (mc->mc->err) {
                printf("Memcache connect error: %s\n", mc->mc->errstr);
                return -1;
        }

	return 0;
}
开发者ID:zhangxj,项目名称:esbi,代码行数:12,代码来源:eng_mc.c


示例19: RedisConnect

bool RedisConnect()
{
	if (sIfConSucess)
	{
		return true;
	}

	bool theRet = false;
	do
	{
		struct timeval timeout = { 2, 0 }; // 2 seconds
		redisContext_ = redisConnectWithTimeout(sRedis_IP, sRedisPort, timeout);
		if (!redisContext_ || redisContext_->err)
		{
			if (redisContext_)
			{
				printf("Redis context connect error \n");
			}
			else
			{
				printf("Connection error: can't allocate redis context\n");
			}

			theRet = false;
			break;
		}

		string auth = Format("auth %s", string(sRedisPassword));
		redisReply* reply = static_cast<redisReply*>(redisCommand(redisContext_, auth.c_str()));

		RedisReplyObjectDeleter replyDeleter(reply);
		if (!reply || string(reply->str) != string("OK"))
		{
			printf("Redis auth error\n");
			theRet = false;
			break;
		}

		theRet = true;
		sIfConSucess = true;

		printf("Connect Redis success\n");

	} while (0);

	if (!theRet && redisContext_)
	{
		RedisErrorHandler();
	}

	return theRet;
}
开发者ID:dreamsxin,项目名称:EasyDarwin,代码行数:52,代码来源:EasyRedisModule.cpp


示例20: main

int main(int argc, char* argv[])
{
    redisContext* g_rctx;
    redisReply *reply;

    struct timeval timeout = { 1, 500000 };
    g_rctx = redisConnectWithTimeout("127.0.0.1", 6379, timeout);
    reply = redisCommand(g_rctx,"SET nfpid %d",getpid());
    printf("%p\n",reply);
    while (1){
        sleep(10);
    }
}
开发者ID:CIRCL,项目名称:lnf-tools,代码行数:13,代码来源:buggynfreader.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ redisContextConnectTcp函数代码示例发布时间:2022-05-30
下一篇:
C++ redisConnect函数代码示例发布时间: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