Skip to content

Commit 317a8b3

Browse files
committed
Add SSL for redis_client_pipeline.
1 parent 7527747 commit 317a8b3

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

lib_acl_cpp/include/acl_cpp/redis/redis_client_pipeline.hpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace acl {
1212

1313
class token_tree;
1414
class socket_stream;
15+
class sslbase_conf;
1516
class redis_client;
1617

1718
typedef enum {
@@ -192,6 +193,7 @@ class redis_pipeline_channel : public thread {
192193
void stop_thread();
193194

194195
public:
196+
redis_pipeline_channel& set_ssl_conf(sslbase_conf* ssl_conf);
195197
redis_pipeline_channel& set_passwd(const char* passwd);
196198
const char* get_addr() const {
197199
return addr_.c_str();
@@ -229,13 +231,13 @@ class redis_pipeline_channel : public thread {
229231
class ACL_CPP_API redis_client_pipeline : public thread {
230232
public:
231233
redis_client_pipeline(const char* addr, box_type_t type = BOX_TYPE_MBOX);
232-
virtual ~redis_client_pipeline(void);
234+
virtual ~redis_client_pipeline();
233235

234236
// Start the pipeline thread
235-
void start_thread(void);
237+
void start_thread();
236238

237239
// Stop the pipeline thread
238-
void stop_thread(void);
240+
void stop_thread();
239241

240242
public:
241243
// Called by redis_command in pipeline mode
@@ -246,9 +248,12 @@ class ACL_CPP_API redis_client_pipeline : public thread {
246248

247249
// Called by redis_command::get_pipeline_message, and can be overrided
248250
// by child class. The box can be tbox, tbox_array, mbox, or fiber_tbox.
249-
virtual box<redis_pipeline_message>* create_box(void);
251+
virtual box<redis_pipeline_message>* create_box();
250252

251253
public:
254+
// Set the ssl conf for the connection with redis internal.
255+
redis_client_pipeline& set_ssl_conf(sslbase_conf* ssl_conf);
256+
252257
// Set the password for connecting the redis server
253258
redis_client_pipeline& set_password(const char* passwd);
254259

@@ -265,17 +270,18 @@ class ACL_CPP_API redis_client_pipeline : public thread {
265270
redis_client_pipeline& set_preconnect(bool yes);
266271

267272
// Get the max hash slot of redis
268-
int get_max_slot(void) const {
273+
int get_max_slot() const {
269274
return max_slot_;
270275
}
271276

272277
protected:
273278
// @override from acl::thread
274-
void* run(void);
279+
void* run();
275280

276281
private:
277282
string addr_; // The default redis address
278283
string passwd_; // Password for connecting redis
284+
sslbase_conf* ssl_conf_;// SSL will be used if not null
279285
box_type_t box_type_; // The type of box
280286
int max_slot_; // The max hash slot for redis cluster
281287
int conn_timeout_; // Timeout to connect redis
@@ -295,13 +301,13 @@ class ACL_CPP_API redis_client_pipeline : public thread {
295301
void set_slot(int slot, const char* addr);
296302

297303
// Set all hash slots' addresses of all redises
298-
void set_all_slot(void);
304+
void set_all_slot();
299305

300306
// Start all pipeline channels threads
301-
void start_channels(void);
307+
void start_channels();
302308

303309
// Stop all pipeline channels threads
304-
void stop_channels(void);
310+
void stop_channels();
305311

306312
// Start one pipeline channel thread with the specified redis address
307313
redis_pipeline_channel* start_channel(const char* addr);
@@ -326,7 +332,7 @@ class ACL_CPP_API redis_client_pipeline : public thread {
326332

327333
/**
328334
* Sample:
329-
* void main_thread(void) {
335+
* void main_thread() {
330336
* acl::redis_client_pipeline pipeline("127.0.0.1:6379");
331337
* pipeline.start_thread();
332338
* // Start some threads

lib_acl_cpp/src/mqtt/mqtt_connect.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void mqtt_connect::set_will_qos(mqtt_qos_t qos) {
8282
break;
8383
default:
8484
logger_error("invalid qos: %d", (int) qos);
85+
break;
8586
}
8687
}
8788

lib_acl_cpp/src/redis/redis_client_pipeline.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ redis_pipeline_channel::~redis_pipeline_channel()
2727
delete box_;
2828
}
2929

30+
redis_pipeline_channel &redis_pipeline_channel::set_ssl_conf(acl::sslbase_conf *ssl_conf)
31+
{
32+
client_->set_ssl_conf(ssl_conf);
33+
return *this;
34+
}
35+
3036
redis_pipeline_channel& redis_pipeline_channel::set_passwd(const char *passwd)
3137
{
3238
if (passwd && *passwd) {
@@ -362,6 +368,12 @@ redis_client_pipeline& redis_client_pipeline::set_retry(bool on)
362368
return *this;
363369
}
364370

371+
redis_client_pipeline& redis_client_pipeline::set_ssl_conf(acl::sslbase_conf *ssl_conf)
372+
{
373+
ssl_conf_ = ssl_conf;
374+
return *this;
375+
}
376+
365377
redis_client_pipeline& redis_client_pipeline::set_password(const char* passwd)
366378
{
367379
if (passwd && *passwd) {
@@ -642,9 +654,13 @@ redis_pipeline_channel* redis_client_pipeline::start_channel(const char *addr)
642654
{
643655
redis_pipeline_channel* channel = NEW redis_pipeline_channel(
644656
*this, addr, conn_timeout_, rw_timeout_, retry_);
657+
658+
channel->set_ssl_conf(ssl_conf_);
659+
645660
if (!passwd_.empty()) {
646661
channel->set_passwd(passwd_);
647662
}
663+
648664
if (channel->start_thread()) {
649665
channels_->insert(addr, channel);
650666
return channel;

0 commit comments

Comments
 (0)