Exemplo n.º 1
0
static void fiber_worker(ACL_FIBER *fiber, void *ctx)
{
	ACL_CHANNEL *chan = ((MYCHAN *) ctx)->chan;

	while (true)
	{
		PKT* pkt = (PKT *) acl_channel_recvp(chan);

		if (pkt == NULL)
		{
			printf("fiber-%d: acl_channel_recvp NULL\r\n",
				acl_fiber_id(fiber));
			break;
		}

		if (pkt->cmd.equal("set", false))
		{
			if (redis_set(*fiber, *chan, *pkt) == false)
			{
				printf("fiber-%d: redis_set error\r\n",
					acl_fiber_id(fiber));
				break;
			}
		}
		else if (pkt->cmd.equal("get", false))
		{
			if (redis_get(*fiber, *chan, *pkt) == false)
			{
				printf("fiber-%d: redis_get error\r\n",
					acl_fiber_id(fiber));
				break;
			}
		}
		else if (pkt->cmd.equal("del", false))
		{
			if (redis_del(*fiber, *chan, *pkt) == false)
			{
				printf("fiber-%d: redis_del error\r\n",
					acl_fiber_id(fiber));
				break;
			}
		}
		else
			printf("unknown cmd: %s\r\n", pkt->cmd.c_str());
	}
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {
	char c;
	redis_client_st *redis_client;
	char config_path[1024];

	if (argc <= 2) {
		printf("usage: ./%s -f xxx.conf", PROGRAME);
		return 1;
	}
	memset(config_path, 0, sizeof(config_path));
	while (-1 != (c = getopt(argc, argv, "f:h"))) {
		switch (c) {
		case 'f':
			snprintf(config_path, sizeof(config_path), "%s", optarg);
			break;
		case '?':
		case 'h':
			printf("usage: ./%s -f xxx.conf", PROGRAME);
			break;
		}

	}

	char *key = "{[email protected]}_test_str";

	redis_client = redis_client_init(config_path);
	if (NULL == redis_client)
		printf("error\n");
	char * avg = "hello asdfasdf asdfas";
	redis_return_st rc = redis_set(redis_client, key, avg);
	assert(rc == REDIS_SUCCESS);
	char *rt = redis_get(redis_client, key, &rc);
	assert(rc == REDIS_SUCCESS);
	assert(strcmp(rt, avg) == 0);
	redis_client_free(redis_client);
	return 1;

}