同步操作将从 acl-dev/acl 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
The redis module in Acl is a powerful redis client library with higth performance, rich interface and easy to use. There are more than 13 C++ classes and over 150 commands in Acl redis, including STRING, HASH, LIST, SET, ZSET, HyperLogLog, PUBSUB, STREAM, TRANSACTION, SCRIPT, CONNECTION, SERVER, etc. User using Acl redis doesn't need care about network comminucation, redis protocol, hash slots caching, etc., just like using C++ STL standard interface.
Acl redis is a part of lib_acl_cpp, so users only need to build the Acl project.
Users can use VS2003/VS2008/VS2010/VS2012/VS2015/VS2017/VS1019
to compile all Acl libraries by opening the Acl projects(acl_cpp_vc2003.sln, acl_cpp_vc2008.sln, acl_cpp_vc2010.sln, acl_cpp_vc2012.sln, acl_cpp_vc2015.sln, acl_cpp_vc2017.sln, acl_cpp_vc2019.sln) with the corresponding VS tools. Due to the dependency in Acl, lib_acl should be compiled first, then lib_protocol, and finally lib_acl_cpp.
#include <stdlib.h>
#include <stdio.h>
#include "acl_cpp/lib_acl.hpp"
static void test_redis_string(acl::redis& cmd, const char* key) {
acl::string val("test_value");
// call redis-server: SET key value
if (!cmd.set(key, val.c_str())) {
printf("redis set error\r\n");
return;
}
// clear the string buf space
val.clear();
// reset the redis command object for reusing it
cmd.clear();
// call redis-server: GET key
if (!cmd.get(key, val)) {
printf("get key error\r\n");
}
}
static void test_redis_key(acl::redis& cmd, const char* key) {
if (cmd.exists(key)) {
printf("key exists\r\n");
} else {
printf("key not exists\r\n");
}
}
int main(void) {
// init socket module for windows
acl::acl_cpp_init();
const char* redis_addr = "127.0.0.1:6379";
int conn_timeout = 10, rw_timeout = 10;
// the redis client connection
acl::redis_client conn(redis_addr, conn_timeout, rw_timeout);
const char* key = "test_key";
// Bind redis_string command with redis connection.
acl::redis cmd(&conn);
test_redis_string(cmd, key);
cmd.clear(); // Clear the temp memory.
// Test redis KEY command with the same redis connection.
test_redis_key(cmd, key);
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include "acl_cpp/lib_acl.hpp"
int main(void) {
// Init socket module for windows
acl::acl_cpp_init();
const char* redis_addr = "127.0.0.1:6379";
int conn_timeout = 10, rw_timeout = 10, max_conns = 100;
// Declare redis connection cluster ojbect.
acl::redis_client_cluster cluster;
cluster.set(redis_addr, max_conns, conn_timeout, rw_timeout);
// Redis operation command.
acl::redis cmd;
// Bind redis command with redis connection cluster.
cmd.set_cluster(&cluster);
const char* key = "test_key";
// Call redis server
test_redis_string(cmd, key);
cmd.clear();
test_redis_key(cmd, key);
return 0;
}
The redis cluster module of Acl supports caching the redis hash slots on client to improve performance, and can dynamically change local hash slots at runtime.
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include "acl_cpp/lib_acl.hpp"
static int __max_conns = 100;
static void* thread_main(void* arg) {
acl::redis_client_cluster* cluster = (acl::redis_client_cluster*) arg;
acl::redis cmd;
cmd.set_cluster(cluster);
const char* key = "test_key";
for (int i = 0; i < 100000; i++) {
test_redis_string(cmd, key);
test_redis_key(cmd, key);
cmd.clear(); // Clear temporary meory to avoid meory overflow.
}
return NULL;
}
int main(void) {
// init socket module for windows
acl::acl_cpp_init();
const char* redis_addr = "127.0.0.1:6379";
int conn_timeout = 10, rw_timeout = 10;
// declare redis cluster ojbect
acl::redis_client_cluster cluster;
cluster.set(redis_addr, __max_conns, conn_timeout, rw_timeout);
pthread_attr_t attr;
pthread_attr_init(&attr);
// create first thread
pthread_t id1;
pthread_create(&id1, &attr, thread_main, &cluster);
// create second thread
pthread_t id2;
pthread_create(&id2, &attr, thread_main, &cluster);
pthread_join(id1, NULL);
pthread_join(id2, NULL);
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include "acl_cpp/lib_acl.hpp"
static void* thread_main(void* arg) {
acl::redis_client_pipeline* pipeline = (acl::redis_client_pipeline*) arg;
acl::redis cmd;
cmd.set_pipeline(pipeline);
acl::string key;
for (int i = 0; i < 100000; i++) {
key.format("test-key-%d", i);
test_redis_string(cmd, key);
test_redis_key(cmd, key);
}
return NULL;
}
int main(void) {
// Init socket module for windows
acl::acl_cpp_init();
const char* redis_addr = "127.0.0.1:6379";
// Declare redis pipeline ojbect
acl::redis_client_pipeline pipeline(redis_addr);
// Start the pipeline thread backend.
pipeline.start_thread();
pthread_attr_t attr;
pthread_attr_init(&attr);
std::vector<pthread_t> threads;
// start some threads to execute redis operations
for (size_t i = 0; i < 100; i++) {
pthread_t id;
int ret = pthread_create(&id, &attr, thread_main, &pipeline);
if (ret == 0) {
threads.push_back(id);
}
}
// wait for all threads to exit
for (std::vector<pthread_t>::iterator it = threads.begin();
it != threads.end(); ++it) {
pthread_join(*it, NULL);
}
// stop the pipeline thread
pipeline.stop_thread();
return 0;
}
Before using Acl redis, you should compile the three basic libraries. Enter the lib_acl, lib_protocol, lib_acl_cpp, and build the lib_acl.a
, lib_protocol.a
and libacl_cpp.a
.
$cd lib_acl; make
$cd lib_protocol; make
$cd lib_acl_cpp; make
You should add the following compilation options in your Makefile:
-I
specify the lib_acl.hpp's parent path, for exmaple: -I./lib_acl_cpp/include
;One Makefile as below:
ACL_PATH=./acl
CFLAGS = -c -g -W -O3 -Wall -Werror -Wshadow \
-Wno-long-long -Wpointer-arith -D_REENTRANT \
-D_POSIX_PTHREAD_SEMANTICS \
-I $(ACL_PATH)/lib_acl_cpp/include
LDFLAGS = -L$(ACL_PATH)/lib_acl_cpp/lib -lacl_cpp \
-L$(ACL_PATH)/lib_protocol/lib -lprotocol \
-L$(ACL_PATH)/lib_acl/lib -lacl \
-lpthread
test: main.o
g++ -o main.o $(LDFLAGS)
main.o: main.cpp
g++ $(CFLAGS) main.cpp -o main.o
Open the VS projects, such as acl_cpp_vc2003.sln, acl_cpp_vc2008.sln, acl_cpp_vc2010.sln, acl_cpp_vc2012.sln, acl_cpp_vc2013.sln, acl_cpp_vc2015.sln, acl_cpp_vc2017.sln, or acl_cpp_vc2019.sln to look at the redis samples project option setting.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。