Beispiel #1
0
static void cb_redis_connect(redisconn_t rc,int err,void *_){
	(void)_;
	if(err == 0){
		printf("connect success\n");
		
		int i = 0;
		/*for( ; i < 1000000; ++i){
			char buf[512];
			snprintf(buf,512,"set key%d %d",i+1,i+1);
			kn_redisCommand(rc,buf,redisset_cb,NULL);
		}
		return;*/
		//发出1000个get
		i = 0;
		for(; i < 1000; ++i){
			char buf[512];
			int key = rand()%10000;
			snprintf(buf,512,"get key%d",key+1);
			kn_redisCommand(rc,buf,redisget_cb,(void*)((uint64_t)key));
		}
		//kn_reg_timer(p,2000,timer_callback2,rc);	
	}else{
		printf("connect fail:%d\n",err);
	}	
}
Beispiel #2
0
static void redisget_cb(redisconn_t rc,redisReply *reply,void *pridata){
	if(!reply) return;
	if(reply->type != REDIS_REPLY_NIL){
		++count;
	}else{
		printf("error:%d,%d\n",reply->type,(int)(uint64_t)pridata);
	}
	char buf[512];
	int key = rand()%10000;
	snprintf(buf,512,"get key%d",key+1);
	kn_redisCommand(rc,buf,redisget_cb,(void*)((uint64_t)key));
	//kn_redisDisconnect(rc);
}
Beispiel #3
0
int lua_redisCommandSync(lua_State *L){
	redisconn_t conn = lua_touserdata(L,1);
	const char *cmd = lua_tostring(L,2);		
	do{
		if(!cmd || strcmp(cmd,"") == 0){
			lua_pushboolean(L,0);
			break;
		}		
		luaRef_t   *cbObj = calloc(1,sizeof(*cbObj)); 	
		*cbObj = toluaRef(L,3);			
		if(REDIS_OK!= kn_redisCommand(conn,cmd,redis_command_cb,cbObj)){
			release_luaRef(cbObj);
			free(cbObj);			
			lua_pushboolean(L,0);
		}else
			lua_pushboolean(L,1);
	}while(0);	
	return 1;
}