Example #1
0
char *iod_get(char *key,int *nv)
{
	int ecode;
	int nk = strlen(key);
	char *value;
	TCRDB * rdb = tcrdbnew();
	int db_port = get_db_port(IO_DATA);
	printf("db_port -- %d\n",db_port);
	if(!tcrdbopen(rdb,LOCALHOST,db_port))
	{
		ecode = tcrdbecode(rdb);
		fprintf(stderr,"iod_get:open %s error -- %s\n",db_port,tcrdberrmsg(ecode));
		return NULL;
	}else{
		printf("db open success!\n");
	    if((value = tcrdbget(rdb,key,nk,nv)) == NULL)
    	{
	    	ecode = tcrdbecode(rdb);
	    	fprintf(stderr,"(key=%s) tt_get error:%s\n",key,tcrdberrmsg(ecode));
			return NULL;
		}else{
	    	printf("(key=%s) tt_get success!\n",key);
			printf("%d bytes read\n",*nv);
    	}
	}
	tcrdbdel(rdb);
	return value;
}
Example #2
0
static VALUE cDB_fetch(int argc, VALUE *argv, VALUE vself){
  VALUE vkey, vdef, vval;
  TCRDB *db;
  char *vbuf;
  int vsiz;
  rb_scan_args(argc, argv, "11", &vkey, &vdef);
  vkey = StringValueEx(vkey);
  Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
  if((vbuf = tcrdbget(db, RSTRING_PTR(vkey), RSTRING_LEN(vkey), &vsiz)) != NULL){
    vval = rb_str_new(vbuf, vsiz);
    tcfree(vbuf);
  } else {
    vval = vdef;
  }
  return vval;
}
Example #3
0
bool MemCacheServerHandler::GetPlatInfo(const string& platID, std::string& dist)
{
	if (g_pInst == NULL || !g_pInst->CanUse())
	{
		return false;
	}

// 	if (uid != 2928562105553271)
// 	{
// 		return false;
// 	}

	int     dbid    = g_pInst->GetServerId(platID);
	TCRDB*  pConn   = g_pInst->GetDB(dbid);
	if (pConn == NULL)
	{
		g_pInst->SetEnbale(false);
		LOG4CXX_ERROR(logger,"memcache_get_connect_null_error");
		return false;
	}

	
	int len  = 0;
	int klen = platID.length();
	char* buffer = (char*)tcrdbget(pConn, platID.c_str(), klen, &len);
	if (buffer == NULL)
	{
		int ecode = tcrdbecode(pConn);
		if (ecode != TTENOREC)
		{
			g_pInst->SetEnbale(false);
			LOG4CXX_ERROR(logger,"memcache_get_ecode_error");
		}
		return false;
	}
	std::string outbuf(buffer, len);
	dist = outbuf;
	free(buffer);	
	//g_pInst->GetCounter().increase("mem_get_user");
	return true;
}
Example #4
0
static int
rdb_get(lua_State *L){
	TCRDB *rdb = rdb_getrdb(L, 1);
	int type = lua_type(L, 2);
	if(type==LUA_TSTRING || type==LUA_TNUMBER){
		size_t ksiz = 0;
		const char *key = rdb_getarg(L, 2, &ksiz);
		int sp;
		char *value = tcrdbget(rdb, key, ksiz, &sp);
		if(value){
			lua_pushlstring(L, value, sp);
			free(value);
		} else lua_pushnil(L);
	} else if(type==LUA_TTABLE){
		TCLIST *list = array2tclist(L, 2);
		int opts = luaL_optint(L, 3, 0);
		TCLIST *pairs = tcrdbmisc(rdb, "getlist", opts, list);
		tclist2hash(L, pairs);
		tclistdel(list);
		tclistdel(pairs);
	} else return luaL_argerror(L, 2, "must be table, string, or number");
	return 1;
}
Example #5
0
int tt_get(char * key,char * zv,value_t vt)
{
	int ecode;
	int nv;
	int rt = 0;
	int nk = strlen(key);
	char * value;
	TCRDB * rdb = tcrdbnew();
	int db_port = get_db_port(vt);
	printf("db_port -- %d\n",db_port);
	if(!tcrdbopen(rdb,LOCALHOST,db_port))
	{
		ecode = tcrdbecode(rdb);
		fprintf(stderr,"tt_get:open %s error -- %s\n",db_port,tcrdberrmsg(ecode));
		rt = 1;
	}
	else
	{
		printf("db open success!\n");
	    if((value = tcrdbget(rdb,key,nk,&nv)) == NULL)
    	{
	    	ecode = tcrdbecode(rdb);
	    	fprintf(stderr,"(key=%s) tt_get error:%s\n",key,tcrdberrmsg(ecode));
	    	rt = 2;
    	}
    	else
    	{
	    	printf("(key=%s) tt_get success!\n",key);
			printf("%d bytes read\n",nv);
			memcpy(zv,value,nv);
			free(value);
    	}
	}
	tcrdbdel(rdb);
	return rt;
}
Example #6
0
 void* db_obj_remote::dbget(const void *kbuf, int ksiz, int *sp)
 {
   return tcrdbget(_hdb,kbuf,ksiz,sp);
 }