Exemplo n.º 1
0
static bool test_zrangebylex(acl::redis_zset& redis, int n)
{
	acl::string key;
	const char* min = "[aaa", *max = "(g";
	std::vector<acl::string> result;

	for (int i = 0; i < n; i++)
	{
		key.format("%s_%d", __keypre.c_str(), i);
		redis.clear();
		int ret = redis.zrangebylex(key.c_str(), min, max, &result);
		if (ret < 0)
		{
			printf("zrangebylex error(%s), key: %s\r\n",
				redis.result_error(), key.c_str());
			return false;
		}
		if (i >= 10)
		{
			result.clear();
			continue;
		}

		std::vector<acl::string>::const_iterator cit;
		for (cit = result.begin(); cit != result.end(); ++cit)
		{
			if (cit != result.begin())
				printf(", ");
			printf("%s", (*cit).c_str());
		}
		printf("\r\n");
	}

	return true;
}
Exemplo n.º 2
0
static bool test_zincrby(acl::redis_zset& redis, int n)
{
	acl::string key;
	double inc = 2.5, result;
	acl::string member;

	for (int i = 0; i < n; i++)
	{
		key.format("%s_%d", __keypre.c_str(), i);

		for (int j = 0; j < 1000; j++)
		{
			member.format("member_%d", j);
			redis.clear();
			if (redis.zincrby(key.c_str(), inc, member.c_str(),
				&result) == false)
			{
				printf("zincrby error, key: %s\r\n", key.c_str());
				return false;
			}
			else if (j < 10 && i * j < 100)
				printf("zincrby ok key: %s, result: %.2f\r\n",
					key.c_str(), result);
		}
	}

	return true;
}
Exemplo n.º 3
0
static bool test_zscore(acl::redis_zset& redis, int n)
{
	acl::string key;
	acl::string member;
	bool ret;
	double result;

	for (int i = 0; i < n; i++)
	{
		key.format("%s_%d", __keypre.c_str(), i);

		for (int j = 0; j < 1000; j++)
		{
			member.format("member_%d", j);
			redis.clear();
			ret = redis.zscore(key.c_str(), member.c_str(),
				result);
			if (ret == false)
			{
				printf("zscore error, key: %s\r\n",
					key.c_str());
				return false;
			}
			else if (j > 0 && j * i < 100)
				printf("zscore ok, key: %s, member:%s, "
					"score: %.2f\r\n", key.c_str(),
					member.c_str(), result);
		}
	}

	return true;
}
Exemplo n.º 4
0
static bool test_zadd(acl::redis_zset& redis, int n)
{
	acl::string key;
	std::map<acl::string, double> members;
	acl::string member;

	for (int i = 0; i < n; i++)
	{
		key.format("%s_%d", __keypre.c_str(), i);

		for (int j = 0; j < 1000; j++)
		{
			member.format("member_%d", j);
			members[member] = j;
		}

		redis.clear();
		int ret = redis.zadd(key, members);
		if (ret < 0)
		{
			printf("add key: %s error\r\n", key.c_str());
			return false;
		}
		else if (i < 10)
			printf("add ok, key: %s, ret: %d\r\n",
				key.c_str(), ret);
		members.clear();
	}

	return true;
}
Exemplo n.º 5
0
static bool test_zrank(acl::redis_zset& redis, int n)
{
	acl::string key;
	acl::string member;

	for (int i = 0; i < n; i++)
	{
		key.format("%s_%d", __keypre.c_str(), i);

		for (int j = 0; j < 1000; j++)
		{
			member.format("member_%d", j);
			redis.clear();
			int ret = redis.zrank(key.c_str(), member.c_str());
			if (ret < 0)
			{
				printf("zrank error, key: %s\r\n", key.c_str());
				return false;
			}
			else if (j > 0 && j * i < 100)
				printf("zrank ok, key: %s, member:%s, "
					"rank: %d\r\n", key.c_str(),
					member.c_str(), ret);
		}
	}

	return true;
}
Exemplo n.º 6
0
static bool test_zrem(acl::redis_zset& redis, int n)
{
	acl::string key;
	acl::string member;
	std::vector<acl::string> members;

	for (int i = 0; i < n; i++)
	{
		key.format("%s_%d", __keypre.c_str(), i);

		for (int j = 900; j < 1000; j++)
		{
			member.format("member_%d", j);
			members.push_back(member);
		}

		redis.clear();
		int ret = redis.zrem(key.c_str(), members);
		if (ret < 0)
		{
			printf("zrem error, key: %s\r\n", key.c_str());
			return false;
		}
		else if (i < 10)
			printf("zrem ok, key: %s, ret: %d\r\n",
				key.c_str(), ret);
	}

	return true;
}
Exemplo n.º 7
0
static bool test_sdiffstore(acl::redis_set& redis, int n)
{
	acl::string key, dest_key("set_dest_key");
	std::vector<acl::string> keys;

	for (int i = 0; i < 10; i++)
	{
		key.format("%s_%d", __keypre.c_str(), i);
		keys.push_back(key);
	}

	for (int i = 0; i < n; i++)
	{
		redis.clear();
		int ret = redis.sdiffstore(dest_key.c_str(), keys);
		if (ret < 0)
		{
			printf("sdiffstore error, dest: %s\r\n",
				dest_key.c_str());
			return false;
		}
		else if (i >= 10)
			continue;

		printf("sdiffstore ok, dest: %s, count: %d\r\n",
			dest_key.c_str(), ret);
	}

	return true;
}
Exemplo n.º 8
0
void CMsnClient::OnDSOk(const acl::string& ns_addr)
{
	acl_assert(ds_client_);
	ns_addr_ = ns_addr;
	delete ds_client_;
	ds_client_ = NULL;

	acl::string addr(ns_addr_.c_str());
	char* ptr = strchr(addr.c_str(), ':');
	if (ptr == NULL || *(ptr + 1) == 0)
	{
		logger_error("invalid ns_addr(%s)", ns_addr.c_str());
		return;
	}
	*ptr++ = 0;
	unsigned short port = atoi(ptr);
	if (port == 0)
	{
		logger_error("invalid ns_port(0)");
		return;
	}

	ns_client_ = NEW CMsnNSClient(account_.c_str(), this);
	ns_client_->Open(addr.c_str(), port, timeout_);
}
Exemplo n.º 9
0
static bool test_sdiff(acl::redis_set& redis, int n)
{
	acl::string key;
	std::vector<acl::string> keys;
	std::vector<acl::string> result;

	for (int i = 0; i < 10; i++)
	{
		key.format("%s_%d", __keypre.c_str(), i);
		keys.push_back(key);
	}

	for (int i = 0; i < n; i++)
	{
		redis.clear();
		int ret = redis.sdiff(keys, &result);
		if (ret < 0)
		{
			printf("sdiff error\r\n");
			return false;
		}
		else if (i < 10)
			printf("sdiff ok, count: %d\r\n", ret);
	}

	return true;
}
Exemplo n.º 10
0
static bool test_sadd(acl::redis_set& redis, int n)
{
	acl::string key;
	std::vector<acl::string> members;
	acl::string member;

	members.reserve(1000);

	for (int j = 0; j < 1000; j++)
	{
		member.format("member_%d", j);
		members.push_back(member);
	}

	for (int i = 0; i < n; i++)
	{
		key.format("%s_%d", __keypre.c_str(), i);

		redis.clear();
		int ret = redis.sadd(key, members);
		if (ret < 0)
		{
			printf("sadd key: %s error\r\n", key.c_str());
			return false;
		}
		else if (i >= 10)
			continue;

		printf("sadd ok, key: %s, ret: %d\r\n", key.c_str(), ret);
	}

	return true;
}
Exemplo n.º 11
0
static bool test_spop(acl::redis_set& redis, int n)
{
	acl::string key;
	acl::string member;

	for (int i = 0; i < n; i++)
	{
		key.format("%s_%d", __keypre.c_str(), i);
		redis.clear();
		bool ret = redis.spop(key.c_str(), member);
		if (redis.eof())
		{
			printf("spop eof, key: %s\r\n", key.c_str());
			return false;
		}
		if (i >= 10)
			continue;

		printf("spop %s, key: %s, member: %s\r\n",
			ret ? "ok" : "empty", key.c_str(),
			ret ? member.c_str() : "");
	}

	return true;
}
Exemplo n.º 12
0
static bool test_sismember(acl::redis_set& redis, int n)
{
	bool ret;
	acl::string key, member;

	for (int i = 0; i < n; i++)
	{
		key.format("%s_%d", __keypre.c_str(), i);

		for (int j = 0; j < 1000; j++)
		{
			member.format("member_%d", j);
			redis.clear();
			ret = redis.sismember(key.c_str(), member.c_str());
			if (redis.eof())
			{
				printf("sismmeber eof, key: %s, member: %s\r\n",
					key.c_str(), member.c_str());
				return false;
			}
			if (i >= 10)
				continue;

			printf("sismember: %s, key: %s, member: %s\r\n",
				ret ? "true" : "false", key.c_str(),
				member.c_str());
		}
	}

	return true;
}
Exemplo n.º 13
0
static void do_copy(const acl::string& from, const acl::string& to)
{
	acl::scan_dir scan;
	if (scan.open(from.c_str()) == false)
	{
		logger_error("open path: %s error: %s",
			from.c_str(), acl::last_serror());
		return;
	}

	const char* name;
	bool  is_file;
	int   nfiles = 0, ndirs = 0, nfiles_copied = 0, ndirs_copied = 0;
	while ((name = scan.next(false, &is_file)) != NULL)
	{
		SKIP(name);

		if (is_file)
		{
			if (cmp_copy(scan, name, to, &nfiles_copied) == false)
			{
				printf(">>cm_copy failed, name: %s\r\n", name);
				break;
			}
			nfiles++;
		}
		else if (check_dir(scan, to, &ndirs_copied) == false)
		{
			printf(">>check_dir failed, name: %s\r\n", name);
			break;
		}
		else
			ndirs++;

		if ((nfiles + ndirs) % 100 == 0)
		{
			printf("current file count: copied %d / scaned %d, "
				"dir count: copied %d / scaned %d\r",
				nfiles_copied, nfiles, ndirs_copied, ndirs);
			fflush(stdout);
		}
	}

	printf("total file count: copyied %d / scaned %d, dir count: "
		"copied %d / scaned %d\r\n", nfiles_copied, nfiles,
		ndirs_copied, ndirs);
}
Exemplo n.º 14
0
void http_client::do_reply(int status, const char* cmd,
	const acl::string& body, bool save)
{
	HTTP_HDR_RES* hdr_res = http_hdr_res_static(status);
	http_hdr_set_keepalive(hdr_req_, hdr_res);
	http_hdr_put_str(&hdr_res->hdr, "Content-Type", "text/json");
	http_hdr_put_int(&hdr_res->hdr, "Content-Length", (int) body.size());

	acl::string buf(body.size() + 256);
	http_hdr_build(&hdr_res->hdr, buf.vstring());
	http_hdr_res_free(hdr_res);
	buf.append(body);

	if (save)
		logger("cmd=[%s], reply: [%s]", cmd, buf.c_str());
	acl_aio_writen(conn_, buf.c_str(), (int) buf.size());
}
Exemplo n.º 15
0
// 程序退出释放动态加载的库
static void __pgsql_dll_unload(void)
{
	if (__pgsql_dll != NULL)
	{
		acl_dlclose(__pgsql_dll);
		__pgsql_dll = NULL;
		logger("%s unload ok", __pgsql_path.c_str());
	}
}
Exemplo n.º 16
0
static bool test_publish(acl::redis_pubsub& redis, int n)
{
	acl::string channel, msg;
	int   ret, i;

	for (i = 0; i < n; i++)
	{
		channel.format("%s_1_%d", __channel_prefix.c_str(), i);
		msg.format("msg_1_%s", channel.c_str());

		redis.clear();
		ret = redis.publish(channel.c_str(), msg.c_str(), msg.length());
		if (ret <= 0)
		{
			printf("publish to %s %s error(%s), ret: %d\r\n",
				channel.c_str(), msg.c_str(),
				redis.result_error(), ret);
			return false;
		}
		else if (i < 10)
			printf("publish to %s %s ok\r\n", channel.c_str(),
				msg.c_str());

		channel.format("%s_2_%d", __channel_prefix.c_str(), i);
		msg.format("msg_2_%s", channel.c_str());
		redis.clear();

		ret = redis.publish(channel.c_str(), msg.c_str(), msg.length());
		if (ret <= 0)
		{
			printf("publish to %s %s error(%s), ret: %d\r\n",
				channel.c_str(), msg.c_str(),
				redis.result_error(), ret);
			return false;
		}
		else if (i < 10)
			printf("publish to %s %s ok\r\n", channel.c_str(),
				msg.c_str());
	}

	printf(">>>publish total: %d\r\n", i * 2);
	return true;
}
Exemplo n.º 17
0
static bool test_mget(acl::redis_string& option, int n)
{
	acl::string key1, key2, key3;
	std::vector<acl::string> result;
	const char* keys[3];

	for (int i = 0; i < n; i++)
	{
		key1.format("key1_%s_%d", __keypre.c_str(), i);
		key2.format("key2_%s_%d", __keypre.c_str(), i);
		key3.format("key3_%s_%d", __keypre.c_str(), i);
		keys[0] = key1.c_str();
		keys[1] = key2.c_str();
		keys[2] = key3.c_str();

		result.clear();
		option.reset();
		if (option.mget(keys, 3, &result) == false)
		{
			printf("mset error\r\n");
			return false;
		}
		else if (i >= 10)
			continue;

		size_t size = option.result_size();
		printf("size: %lu\r\n", (unsigned long) size);

		size_t j;
		for (j = 0; j < size; j++)
		{
			const char* val = option.result_value(j);
			printf("mget ok, %s=%s\r\n",
				keys[j], val ? val : "null");
		}

		std::vector<acl::string>::const_iterator it= result.begin();
		for (j = 0; it != result.end(); ++it, j++)
			printf("mget %s=%s\r\n", keys[j], (*it).c_str());
	}

	return true;
}
Exemplo n.º 18
0
void CMsnADLPayload::ToString(CMsnClient* client, acl::string& out,
	const std::list<CMembership*>& memberShips)
{
	std::list<MSN_DOMAIN*> domains;
	acl::string buf;

	// 遍历所有的联系人成员

	std::list<CMembership*>::const_iterator cit = memberShips.begin();
	for (; cit != memberShips.end(); cit++)
	{
		const CMembership* memberShip = *cit;

		const std::list<Member*>& members = memberShip->GetMembers();
		std::list<Member*>::const_iterator cit2 = members.begin();
		for (; cit2 != members.end(); cit2++)
			AddToDomain(domains, *cit2);
	}

	buf = "<ml l='1'>";

	std::list<MSN_DOMAIN*>::const_iterator cit2 = domains.begin();
	for (; cit2 != domains.end(); cit2++)
	{
		AddXmlNode(buf, *cit2);
		if (buf.length() >= 4096)
		{
			buf << "</ml>";
			out << "ADL " << client->Sid()
				<< " " << (int) buf.length() << "\r\n";
			out.append(buf);
			buf = "<ml l='1'>";
		}
	}

	//buf.format_append("<d n='live.com'><c n='support.service' t='32'>"
	//	"<s l='2' n='IM' /><s l='2' n='PE' /></c></d>");
	//buf.format_append("<d n='live.com'><c n='support.service' l='2' t='1'/></d>");
	buf << "</ml>";
	out << "ADL " << client->Sid() << " " << (int) buf.length() << "\r\n";
	out.append(buf);
	ClearDomain(domains);
}
Exemplo n.º 19
0
static bool create_db(void)
{
	acl::db_sqlite db(__dbfile);

	if (db.open() == false)
	{
		printf("open dbfile: %s error\r\n", __dbfile.c_str());
		return (false);
	}
	db.show_conf();
	return (tbl_create(db));
}
Exemplo n.º 20
0
static bool test_addjob(acl::disque& cmd, const acl::disque_cond& cond, int i)
{
	acl::string job;
	int timeout = 0;
	const char* jobid;

	job.format("job_%s_%d", __jobpre.c_str(), i);
	cmd.clear();
	jobid = cmd.addjob(__queue, job, timeout, &cond);
	if (jobid == NULL)
	{
		printf("addjob queue: %s error: %s\r\n",
			__queue.c_str(), cmd.result_error());
		return false;
	}
	else if (i < 10)
		printf("addjob queue: %s ok, jobid: %s\r\n",
			__queue.c_str(), jobid);

	return true;
}
Exemplo n.º 21
0
static bool test_msetnx(acl::redis_string& option, int n)
{
	acl::string key1, key2, key3;
	acl::string val1, val2, val3;
	std::map<acl::string, acl::string> objs;
	int   ret;

	for (int i = 0; i < n; i++)
	{
		key1.format("key1_%s_%d", __keypre.c_str(), i);
		key2.format("key2_%s_%d", __keypre.c_str(), i);
		key3.format("key3_%s_%d", __keypre.c_str(), i);

		val1.format("val1_%s", key1.c_str());
		val2.format("val2_%s", key2.c_str());
		val3.format("val3_%s", key3.c_str());

		objs[key1] = val1;
		objs[key2] = val2;
		objs[key3] = val3;

		option.reset();
		ret = option.msetnx(objs);
		if (ret < 0)
		{
			printf("mset error\r\n");
			return false;
		}
		else if (i < 10)
		{
			printf("msetnx ret: %d, %s=%s, %s=%s, %s=%s\r\n", ret,
				key1.c_str(), val1.c_str(),
				key2.c_str(), val2.c_str(),
				key3.c_str(), val3.c_str());
		}
		objs.clear();
	}

	return true;
}
Exemplo n.º 22
0
static bool test_getjob(acl::disque& cmd, int max, int& i, int count)
{
	if (i >= max)
		return true;

	std::vector<acl::string> queues;
	size_t timeout = 10;

	queues.push_back(__queue);

	cmd.clear();
	const std::vector<acl::disque_job*>* jobs =
		cmd.getjob(queues, timeout, count);
	if (jobs == NULL)
	{
		printf("getjob queue: %s error: %s\r\n",
			__queue.c_str(), cmd.result_error());
		return false;
	}

	std::vector<acl::string> job_ids;
	std::vector<acl::disque_job*>::const_iterator cit1;
	for (cit1 = jobs->begin(); cit1 != jobs->end(); ++cit1)
	{
		const char* jobid = (*cit1)->get_id();
		if (*jobid)
			job_ids.push_back(jobid);
	}

	if (!job_ids.empty() && !test_ackjob(cmd, job_ids, i))
		return false;

	i += jobs->size();

	if (i >= 2 * (int) count)
		return true;

	printf("%s -> addr: %s, tid: %lu, count: %d, %d\r\n", __FUNCTION__,
		cmd.get_client_addr(), acl::thread::thread_self(),
		(int) count, (int) jobs->size());

	std::vector<acl::disque_job*>::const_iterator cit2;
	for (cit2 = jobs->begin(); cit2 != jobs->end(); ++cit2)
	{
		printf("\tid: %s\r\n", (*cit2)->get_id());
		printf("\tqueue: %s\r\n", (*cit2)->get_queue());
		printf("\tjob: %s\r\n", (*cit2)->get_body().c_str());
	}

	return true;
}
Exemplo n.º 23
0
static bool test_addjob(acl::disque& cmd, const acl::disque_cond& cond, int i)
{
	acl::string job;
	int timeout = 0;
	const char* jobid;

	job.format("job_%s_%d", __jobpre.c_str(), i);
	cmd.clear();
	jobid = cmd.addjob(__queue, job, timeout, &cond);
	if (jobid == NULL)
	{
		printf("addjob queue: %s error: %s\r\n",
			__queue.c_str(), cmd.result_error());
		return false;
	}
	else if (i >= 10)
		return true;

	printf("addjob queue: %s ok, jobid: %s\r\n", __queue.c_str(), jobid);
	printf("%s -> addr: %s, tid: %lu\r\n", __FUNCTION__,
		cmd.get_client_addr(), acl::thread::thread_self());

	return true;
}
Exemplo n.º 24
0
static bool test_expire(acl::redis_key& redis, int i)
{
	acl::string key;

	key.format("%s_%d", __keypre.c_str(), i);
	redis.clear();
	if (redis.expire(key.c_str(), 100) < 0)
	{
		printf("expire key: %s error\r\n", key.c_str());
		return false;
	}
	else if (i < 10)
		printf("expire ok, key: %s\r\n", key.c_str());
	return true;
}
Exemplo n.º 25
0
static bool test_get(acl::redis& cmd, int i)
{
	cmd.reset();

	acl::string key;
	key.format("%s_%d", __keypre.c_str(), i);

	acl::string value;

	bool ret = cmd.get(key.c_str(), value);
	if (i < 10)
		printf("get key: %s, value: %s %s, len: %d\r\n",
			key.c_str(), value.c_str(), ret ? "ok" : "error",
			(int) value.length());
	return ret;
}
Exemplo n.º 26
0
static bool test_exists(acl::redis_key& redis, int n)
{
	acl::string key;

	for (int i = 0; i < n; i++)
	{
		key.format("%s_%d", __keypre.c_str(), i);
		redis.clear();
		if (redis.exists(key.c_str()) == false)
			printf("no exists key: %s\r\n", key.c_str());
		else
			printf("exists key: %s\r\n", key.c_str());
	}

	return true;
}
Exemplo n.º 27
0
static bool test_type(acl::redis_key& redis, int i)
{
	acl::string key;

	key.format("%s_%d", __keypre.c_str(), i);
	redis.clear();
	acl::redis_key_t ret = redis.type(key.c_str());
	if (ret == acl::REDIS_KEY_UNKNOWN)
	{
		printf("unknown type key: %s\r\n", key.c_str());
		return false;
	}
	else if (i < 10)
		printf("type ok, key: %s, ret: %d\r\n", key.c_str(), ret);
	return true;
}
Exemplo n.º 28
0
static bool test_del(acl::redis_key& redis, int i)
{
	acl::string key;

	key.format("%s_%d", __keypre.c_str(), i);
	redis.clear();
	int ret = redis.del(key.c_str(), NULL);
	if (ret < 0)
	{
		printf("del key: %s error\r\n", key.c_str());
		return false;
	}
	else if (i < 10)
		printf("del ok, key: %s\r\n", key.c_str());
	return true;
}
Exemplo n.º 29
0
static bool test_ttl(acl::redis_key& redis, int i)
{
	acl::string key;
	int ttl;

	key.format("%s_%d", __keypre.c_str(), i);
	redis.clear();
	if ((ttl = redis.ttl(key.c_str())) < 0)
	{
		printf("get ttl key: %s error\r\n", key.c_str());
		return false;
	}
	else if (i < 10)
		printf("ttl ok, key: %s, ttl: %d\r\n", key.c_str(), ttl);
	return true;
}
Exemplo n.º 30
0
static bool test_set(acl::redis& cmd, int i)
{
	cmd.reset();

	acl::string key;
	key.format("%s_%d", __keypre.c_str(), i);

	acl::string value;
	value.format("value_%s", key.c_str());

	bool ret = cmd.set(key.c_str(), value.c_str());
	return ret;
	if (i < 10)
		printf("set key: %s, value: %s %s\r\n", key.c_str(),
			value.c_str(), ret ? "ok" : "error");
	return ret;
}