Exemple #1
0
	string TTClient::get(string key){

	    LOG_DEBUG("TTClient::get => key=: "<<key);
	    char* value = NULL;
	    string ret;

	    value = tcrdbget2(tcrdbPtr_, key.c_str());

	    if(value){
		LOG_DEBUG("TTClient::tcrdbget2 ==> key: "<<key<<" return value : ["<<value<<"]");
		ret = value;
		delete value;
	    } else {
		LOG_DEBUG("TTClient::tcrdbget2 ==> key: "<<key<<" return null value ");
		int code = tcrdbecode(tcrdbPtr_);
		if(code != TTESUCCESS){
		    //网络异常,重试
		    LOG_ERROR("TTClient::tcrdbecode => key: "<<key<<" failure : recv error code: "<<code);
		    reOpen();
		    ret = reGetFromTT(key); //重新获取
		}
		else   //从TT返回成功,不做任何处理
		{
		    LOG_DEBUG("TTClient::tcrdbecode ==> key: "<<key<<"return code == "<<code);
		}			

           }

	    return ret;
	}
bool QCrawlerDB::getUrlStatus(QString url, QCrawlerUrl::Status *url_status) {
    bool ret = false;

    int status = 0;

    char *value;
    value = tcrdbget2(url_hash_db, url.toUtf8().constData());
    if(value){
        status = atoi(value);
        if (status < -5) {
            status = -5;
        }

        *url_status = (QCrawlerUrl::Status)status;
        ret = true;

        free(value);
    } else {
        int ecode = tcrdbecode(url_hash_db);
        if (ecode == 7) {
            *url_status = QCrawlerUrl::NOT_EXIST;
            ret = true;
        } else {
            fprintf(stderr, "get url status error: %s", tcrdberrmsg(ecode));
            ret = false;
        }
    }

    return ret;
}
static VALUE cDB_get(VALUE vself, VALUE vkey){
  VALUE vval;
  char *vbuf;
  TCRDB *db;
  Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);

  vkey = StringValueEx(vkey);
  if(!(vbuf = tcrdbget2(db, RSTRING_PTR(vkey)))) return Qnil;
  vval = rb_str_new2(vbuf);
  tcfree(vbuf);
  return vval;
}
Exemple #4
0
bool QStore::get_thumb(const std::string &thumb_key, std::string &thumb)
{
    assert(need_media_db);

    char *value = tcrdbget2(media_db, thumb_key.c_str());
    if (value) {
        thumb.append(value);
        free(value);
        return true;
    } else {
        return false;
    }
}
static VALUE cDB_values(VALUE vself){
  VALUE vary;
  TCRDB *db;
  char *kxstr, *vxstr;
  Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
  vary = rb_ary_new2(tcrdbrnum(db));
  tcrdbiterinit(db);
  while((kxstr = tcrdbiternext2(db)) != NULL){
    vxstr = tcrdbget2(db, kxstr);
    rb_ary_push(vary, rb_str_new2(vxstr));
    tcfree(vxstr);
    tcfree(kxstr);
  }
  return vary;
}
static VALUE cDB_each_value(VALUE vself){
  VALUE vrv;
  TCRDB *db;
  char *kxstr, *vxstr;
  if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given");
  Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
  vrv = Qnil;
  tcrdbiterinit(db);
  while((kxstr = tcrdbiternext2(db)) != NULL){
    vxstr = tcrdbget2(db, kxstr);
    vrv = rb_yield_values(1, rb_str_new2(vxstr));
    tcfree(vxstr);
    tcfree(kxstr);
  }
  return vrv;
}
Exemple #7
0
	//从TT重新获取一次secketkey
	string  TTClient::reGetFromTT(const string& key)
	{
	    string strTT;
	    char* value = tcrdbget2(tcrdbPtr_, key.c_str());
	    if(value){
		strTT = value;
		delete value;
		LOG_DEBUG("TTClient::reGetFromTT ==> key: "<<key<<" return code : ["<<strTT<<"]");
	    }	
	    else {
		int code = tcrdbecode(tcrdbPtr_);  //获取code码
		if(code != TTESUCCESS){  
		    LOG_ERROR("TTClient::reGetFromTT => recv error  code : "<<code);	
		}
		else //返回成功,不做任何处理
		{
		    LOG_DEBUG("TTClient::reGetFromTT ==> key: "<<key<<" return code == "<<code);
		}
	    }
	    return strTT;
	}