Skip to content

Commit

Permalink
optimize some codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ubuntu14 committed Aug 26, 2015
1 parent bfebe1b commit 2fb84c4
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 53 deletions.
18 changes: 7 additions & 11 deletions lib_acl/samples/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CFLAGS = -c -g -W -Wall -Wcast-qual \
###########################################################
#Check system:
# Linux, SunOS, Solaris, BSD variants, AIX, HP-UX
SYSLIB = -lpthread -rdynamic
SYSLIB = -lpthread
CHECKSYSRES = @echo "Unknow system type!";exit 1
UNIXNAME = $(shell uname -sm)

Expand Down Expand Up @@ -52,34 +52,30 @@ endif
# For FreeBSD
ifeq ($(findstring FreeBSD, $(UNIXNAME)), FreeBSD)
CFLAGS += -DFREEBSD
SYSLIB += -lcrypt
SYSLIB += -lcrypt -rdynamic
endif

# For Darwin
ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin)
CFLAGS += -DMACOSX -Wno-invalid-source-encoding \
-Wno-extended-offsetof
SYSLIB += -rdynamic
UNIXTYPE = MACOSX
endif

#Path for Linux
ifeq ($(findstring Linux, $(UNIXNAME)), Linux)
CFLAGS += -DLINUX2
SYSLIB += -lcrypt
SYSLIB += -lcrypt -rdynamic
endif

# For MINGW
ifeq ($(findstring MINGW, $(UNIXNAME)), MINGW)
SYSLIB = -lpthread-2
CFLAGS += -DLINUX2 -DMINGW
SYSLIB = -lpthread-2 -rdynamic
UNIXTYPE = LINUX
endif

# For Darwin
ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin)
CFLAGS += -DMACOSX
endif

#Path for SunOS
ifeq ($(findstring SunOS, $(UNIXNAME)), SunOS)
ifeq ($(findstring 86, $(UNIXNAME)), 86)
Expand All @@ -89,14 +85,14 @@ ifeq ($(findstring SunOS, $(UNIXNAME)), SunOS)
SYSLIB += -lsocket -lnsl -lrt
endif
CFLAGS += -DSUNOS5
SYSLIB += -lcrypt
SYSLIB += -lcrypt -rdynamic
endif

#Path for HP-UX
ifeq ($(findstring HP-UX, $(UNIXNAME)), HP-UX)
CFLAGS += -DHP_UX -DHPUX11
PLAT_NAME=hp-ux
SYSLIB += -lcrypt
SYSLIB += -lcrypt -rdynamic
endif

#Find system type.
Expand Down
4 changes: 4 additions & 0 deletions lib_acl_cpp/changes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
�޸���ʷ�б���

------------------------------------------------------------------------
350) 2015.8.26
350.1) feature: string ���ڽ��� base64 ����ʱ����Ҫ�Զ���β������ \0 �Է�ֹʹ����
���������

349) 2015.8.24
349.1) bugfix: redis_command/redis_key/redis_hash/redis_set/redis_zset ��
���������У����ܷ���˻᷵�� cursor Ϊ > 0 �������Ϊ�յ��������Ҫ������������д���
Expand Down
9 changes: 6 additions & 3 deletions lib_acl_cpp/include/acl_cpp/stdlib/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,22 +1052,25 @@ class ACL_CPP_API string
/**
* 如果当前对象的缓冲区中的数据是经 base64 编码的,则此函数将这些
* 数据进行解码
* @return {string&} 当前对象的引用
* @return {string&} 当前对象的引用,如果解码出错,则内部缓冲区会被自动清空,
* 调用 string::empty() 返回 true
*/
string& base64_decode(void);

/**
* 将输入的 base64 编码的数据进行解码并存入当前对象的缓冲区中
* @param s {const char*} 经 base64 编码的源数据
* @return {string&} 当前对象的引用
* @return {string&} 当前对象的引用,如果解码出错,则内部缓冲区会被自动清空,
* 调用 string::empty() 返回 true
*/
string& base64_decode(const char* s);

/**
* 将输入的 base64 编码的数据进行解码并存入当前对象的缓冲区中
* @param ptr {const void*} 经 base64 编码的源数据
* @param len {size_t} ptr 数据长度
* @return {string&} 当前对象的引用
* @return {string&} 当前对象的引用,如果解码出错,则内部缓冲区会被自动清空,
* 调用 string::empty() 返回 true
*/
string& base64_decode(const void* ptr, size_t len);

Expand Down
4 changes: 2 additions & 2 deletions lib_acl_cpp/samples/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ endif
ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin)
CFLAGS += -DMACOSX -Wno-invalid-source-encoding \
-Wno-extended-offsetof
UNIXTYPE = MACOSX
SYSLIB += -rdynamic
UNIXTYPE = MACOSX
endif

#Path for Linux
Expand All @@ -56,7 +56,7 @@ ifeq ($(findstring Linux, $(OSNAME)), Linux)
RPATH = linux64
endif
CFLAGS += -DLINUX2
SYSLIB += -rdynamic
SYSLIB += -rdynamic
endif

# For MINGW
Expand Down
19 changes: 16 additions & 3 deletions lib_acl_cpp/samples/redis/redis_hash/redis_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ static void usage(const char* procname)
"-C connect_timeout[default: 10]\r\n"
"-I rw_timeout[default: 10]\r\n"
"-S [if slice request, default: no]\r\n"
"-c [cluster mode]\r\n"
"-a cmd[hmset|hmget|hset|hsetnx|hget|hgetall|hincrby|hincrbyfloat|hkeys|hexists|hlen|hdel]\r\n",
procname);
}
Expand All @@ -375,9 +376,9 @@ int main(int argc, char* argv[])
{
int ch, n = 1, conn_timeout = 10, rw_timeout = 10;
acl::string addr("127.0.0.1:6379"), cmd;
bool slice_req = false;
bool slice_req = false, cluster_mode = false;

while ((ch = getopt(argc, argv, "hs:n:C:I:a:S")) > 0)
while ((ch = getopt(argc, argv, "hs:n:C:I:a:Sc")) > 0)
{
switch (ch)
{
Expand All @@ -402,15 +403,27 @@ int main(int argc, char* argv[])
case 'S':
slice_req = true;
break;
case 'c':
cluster_mode = true;
break;
default:
break;
}
}

acl::acl_cpp_init();

acl::redis_client_cluster cluster(conn_timeout, rw_timeout);
cluster.set(addr.c_str(), 100);

acl::redis_client client(addr.c_str(), conn_timeout, rw_timeout);
client.set_slice_request(slice_req);
acl::redis_hash redis(&client);

acl::redis_hash redis;
if (cluster_mode)
redis.set_cluster(&cluster, 100);
else
redis.set_client(&client);

bool ret;

Expand Down
20 changes: 17 additions & 3 deletions lib_acl_cpp/samples/redis/redis_hyperloglog/redis_hyperloglog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static void usage(const char* procname)
"-C connect_timeout[default: 10]\r\n"
"-I rw_timeout[default: 10]\r\n"
"-S [if slice request, default: no]\r\n"
"-c [use cluster mode]\r\n"
"-a cmd[pfadd|pfcount|pfmerge]\r\n",
procname);
}
Expand All @@ -105,9 +106,9 @@ int main(int argc, char* argv[])
{
int ch, n = 1, conn_timeout = 10, rw_timeout = 10;
acl::string addr("127.0.0.1:6379"), cmd;
bool slice_req = false;
bool slice_req = false, cluster_mode = false;

while ((ch = getopt(argc, argv, "hs:n:C:I:a:S")) > 0)
while ((ch = getopt(argc, argv, "hs:n:C:I:a:Sc")) > 0)
{
switch (ch)
{
Expand All @@ -132,15 +133,28 @@ int main(int argc, char* argv[])
case 'S':
slice_req = true;
break;
case 'c':
cluster_mode = true;
break;
default:
break;
}
}

acl::acl_cpp_init();

acl::redis_client_cluster cluster(conn_timeout, rw_timeout);
cluster.set(addr.c_str(), 100);

acl::redis_client client(addr.c_str(), conn_timeout, rw_timeout);
client.set_slice_request(slice_req);
acl::redis_hyperloglog redis(&client);

acl::redis_hyperloglog redis;

if (cluster_mode)
redis.set_cluster(&cluster, 100);
else
redis.set_client(&client);

bool ret;

Expand Down
19 changes: 17 additions & 2 deletions lib_acl_cpp/samples/redis/redis_key/redis_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static void usage(const char* procname)
"-n count\r\n"
"-C connect_timeout[default: 10]\r\n"
"-T rw_timeout[default: 10]\r\n"
"-c [use cluster mode]\r\n"
"-a cmd[del|expire|ttl|exists|type|all]\r\n",
procname);
}
Expand All @@ -122,8 +123,9 @@ int main(int argc, char* argv[])
{
int ch, n = 1, conn_timeout = 10, rw_timeout = 10;
acl::string addr("127.0.0.1:6379"), cmd;
bool cluster_mode = false;

while ((ch = getopt(argc, argv, "hs:n:C:T:a:")) > 0)
while ((ch = getopt(argc, argv, "hs:n:C:T:a:c")) > 0)
{
switch (ch)
{
Expand All @@ -145,14 +147,27 @@ int main(int argc, char* argv[])
case 'a':
cmd = optarg;
break;
case 'c':
cluster_mode = true;
break;
default:
break;
}
}

acl::acl_cpp_init();

acl::redis_client_cluster cluster(conn_timeout, rw_timeout);
cluster.set(addr.c_str(), 100);

acl::redis_client client(addr.c_str(), conn_timeout, rw_timeout);
acl::redis_key redis(&client);

acl::redis_key redis;

if (cluster_mode)
redis.set_cluster(&cluster, 100);
else
redis.set_client(&client);

bool ret;

Expand Down
17 changes: 16 additions & 1 deletion lib_acl_cpp/samples/redis/redis_list/redis_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ static void usage(const char* procname)
"-C connect_timeout[default: 10]\r\n"
"-I rw_timeout[default: 10]\r\n"
"-S [if slice request, default: no]\r\n"
"-c [use cluster mode]\r\n"
"-a cmd[lpush|rpush|lpushx|rpushx|lrange|rpop|lpop|blpop|brpop|rpoplpush|brpoplpush|lrem|ltrim|llen|lindex|lset|linsert_before|linsert_after]\r\n",
procname);
}
Expand All @@ -709,8 +710,9 @@ int main(int argc, char* argv[])
{
int ch, n = 50, conn_timeout = 10, rw_timeout = 10;
acl::string addr("127.0.0.1:6379"), cmd("all");
bool cluster_mode = false;

while ((ch = getopt(argc, argv, "hs:n:C:T:a:")) > 0)
while ((ch = getopt(argc, argv, "hs:n:C:T:a:c")) > 0)
{
switch (ch)
{
Expand All @@ -732,15 +734,28 @@ int main(int argc, char* argv[])
case 'a':
cmd = optarg;
break;
case 'c':
cluster_mode = true;
break;
default:
break;
}
}

acl::acl_cpp_init();

acl::redis_client_cluster cluster(conn_timeout, rw_timeout);
cluster.set(addr.c_str(), 100);

acl::redis_client client(addr.c_str(), conn_timeout, rw_timeout);

acl::redis_list redis(&client);

if (cluster_mode)
redis.set_cluster(&cluster, 100);
else
redis.set_client(&client);

bool ret;

if (cmd == "lpush")
Expand Down
19 changes: 17 additions & 2 deletions lib_acl_cpp/samples/redis/redis_pubsub/redis_pubsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ static void usage(const char* procname)
"-n count\r\n"
"-C connect_timeout[default: 10]\r\n"
"-I rw_timeout[default: 0]\r\n"
"-c [use cluster mode]\r\n"
"-a cmd[subscribe|publish]\r\n",
procname);
}
Expand All @@ -127,8 +128,9 @@ int main(int argc, char* argv[])
{
int ch, n = 1, conn_timeout = 10, rw_timeout = 0;
acl::string addr("127.0.0.1:6379"), cmd;
bool cluster_mode = false;

while ((ch = getopt(argc, argv, "hs:n:C:I:a:")) > 0)
while ((ch = getopt(argc, argv, "hs:n:C:I:a:c")) > 0)
{
switch (ch)
{
Expand All @@ -150,15 +152,28 @@ int main(int argc, char* argv[])
case 'a':
cmd = optarg;
break;
case 'c':
cluster_mode = true;
break;
default:
break;
}
}

acl::acl_cpp_init();
acl::log::stdout_open(true);

acl::redis_client_cluster cluster(conn_timeout, rw_timeout);
cluster.set(addr.c_str(), 100);

acl::redis_client client(addr.c_str(), conn_timeout, rw_timeout);
acl::redis_pubsub redis(&client);

acl::redis_pubsub redis;

if (cluster_mode)
redis.set_cluster(&cluster, 100);
else
redis.set_client(&client);

bool ret;

Expand Down
Loading

0 comments on commit 2fb84c4

Please sign in to comment.