Skip to content

Commit 34bb6a4

Browse files
committed
acl 3.1.1 version release
1 parent fb5ccdd commit 34bb6a4

File tree

1 file changed

+62
-3
lines changed

1 file changed

+62
-3
lines changed

lib_acl_cpp/samples/redis/README.md

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ static void test_redis_string(acl::redis_string& cmd, const char* key)
4444
// call redis-server: GET key
4545
if (cmd.get(key, val) == false)
4646
printf("get key error\r\n");
47-
4847
}
4948

5049
static void test_redis_key(acl::redis_key& cmd, const char* key)
5150
{
52-
if (cmd_key.exists(key) == false)
51+
if (cmd.exists(key) == false)
5352
printf("key not exists\r\n");
5453
else
5554
printf("key exists\r\n");
@@ -99,12 +98,72 @@ int main(void)
9998
// call redis server
10099
test_redis_string(cmd_string, key);
101100
test_redis_key(cmd_key, key);
102-
103101
}
104102
```
105103
The redis cluster support caching the redis hash-slot in client for performance, and can dynamic add redis server nodes in running.
106104

105+
### another way to use acl redis easily
106+
The acl::redis class inherits from all the other acl redis command class, which includes all the redis client commands. So you can use the acl::redis class just as you can do in all the redis-client-commands class.
107+
108+
```c++
109+
#include <stdlib.h>
110+
#include <stdio.h>
111+
#include "acl_cpp/lib_acl.hpp"
112+
113+
static void test_redis_string(acl::redis& cmd, const char* key)
114+
{
115+
acl::string val("test_value");
116+
117+
// call redis-server: SET key value
118+
if (cmd.set(key, val.c_str()) == false)
119+
{
120+
printf("redis set error\r\n");
121+
return;
122+
}
123+
124+
// clear the string buf space
125+
val.clear();
126+
127+
// reset the redis command object for reusing it
128+
cmd.reset();
129+
130+
// call redis-server: GET key
131+
if (cmd.get(key, val) == false)
132+
printf("get key error\r\n");
133+
}
134+
135+
static void test_redis_key(acl::redis& cmd, const char* key)
136+
{
137+
if (cmd.exists(key) == false)
138+
printf("key not exists\r\n");
139+
else
140+
printf("key exists\r\n");
141+
}
142+
143+
int main(void)
144+
{
145+
const char* redis_addr = "127.0.0.1:6379";
146+
int conn_timeout = 10, rw_timeout = 10, max_conns = 100;
147+
148+
// declare redis cluster ojbect
149+
acl::redis_cluster cluster;
150+
cluster.set(redis_addr, max_conns);
151+
152+
// redis operation command
153+
acl::redis cmd;
154+
155+
// bind redis command with redis cluster
156+
cmd.set_cluster(&cluster, max_conns);
157+
158+
const char* key = "test_key";
159+
160+
// call redis server
161+
test_redis_string(cmd, key);
162+
test_redis_key(cmd, key);
163+
}
164+
```
107165
### add acl redis to your projects
166+
Before you use the acl redis, you should compile the three base libraries which redis depending on. Enter the lib_acl, lib_protocol, lib_acl_cpp, and build the lib_acl.a, lib_protocol.a and lib_acl_cpp.a.
108167
#### On UNIX/LINUX
109168
In your Makefile, you should add below compiling flags:
110169
-DLINUX2 for LINUX, -DFREEBSD for FreeBSD, -DMACOSX for MAXOS, -DSUNOS5 for Solaris X86;

0 commit comments

Comments
 (0)