Skip to content

Commit f38bc10

Browse files
committed
fix
1 parent 73f0158 commit f38bc10

File tree

8 files changed

+81
-118
lines changed

8 files changed

+81
-118
lines changed

include/cppredis/client.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,15 +463,15 @@ namespace cpp_redis {
463463
}
464464

465465
template<typename...Args>
466-
VALUES multi_get_keys(Args&&...key)
466+
std::vector<std::string> multi_get_keys(Args&&...key)
467467
{
468468
constexpr auto Size = sizeof...(key);
469469
static_assert(is_sting_, "This API Support String Request");
470470
if (Size ==0){
471471
return {};
472472
}
473473

474-
for_each_args(key);
474+
for_each_args(std::forward<Args>(key)...);
475475
if (keys_.empty()){
476476
return {};
477477
}
@@ -489,7 +489,7 @@ namespace cpp_redis {
489489
return false;
490490
}
491491

492-
for_each_args(key_value);
492+
for_each_args(std::forward<Args>(key_value)...);
493493
if (keys_.empty()) {
494494
return false;
495495
}
@@ -506,7 +506,7 @@ namespace cpp_redis {
506506
return 0;
507507
}
508508

509-
for_each_args(key_value);
509+
for_each_args(std::forward<Args>(key_value)...);
510510
if (keys_.empty()) {
511511
return 0;
512512
}

include/cppredis/client_interface.hpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,17 @@ namespace cpp_redis {
188188
return false;
189189
}
190190

191-
virtual VALUES multi_get_keys(KEYS&& keys)
191+
virtual std::vector<std::string> multi_get_keys(std::vector<std::string>&& keys)
192192
{
193193
return {};
194194
}
195195

196-
virtual bool multi_set_keys(KEYS&& keys)
196+
virtual bool multi_set_keys(std::vector<std::string>&& keys)
197197
{
198198
return false;
199199
}
200200

201-
virtual int multi_set_if_not_set(KEYS&& keys)
201+
virtual int multi_set_if_not_set(std::vector<std::string>&& keys)
202202
{
203203
return false;
204204
}
@@ -360,12 +360,12 @@ namespace cpp_redis {
360360
return INT32_MAX;
361361
}
362362

363-
virtual int set_add(KEYS&& keys)
363+
virtual int set_add(std::vector<std::string>&& keys)
364364
{
365365
return 0;
366366
}
367367

368-
virtual int set_delete_elem(KEYS&& keys)
368+
virtual int set_delete_elem(std::vector<std::string>&& keys)
369369
{
370370
return 0;
371371
}
@@ -380,22 +380,22 @@ namespace cpp_redis {
380380
return "";
381381
}
382382

383-
virtual RESULTS_TYPE set_sinter(KEYS&& keys)
383+
virtual RESULTS_TYPE set_sinter(std::vector<std::string>&& keys)
384384
{
385385
return {};
386386
}
387387

388-
virtual int set_inter_store(KEYS&& keys)
388+
virtual int set_inter_store(std::vector<std::string>&& keys)
389389
{
390390
return 0;
391391
}
392392

393-
virtual RESULTS_TYPE set_union(KEYS&& keys)
393+
virtual RESULTS_TYPE set_union(std::vector<std::string>&& keys)
394394
{
395395
return {};
396396
}
397397

398-
virtual int set_union_store(KEYS&& keys)
398+
virtual int set_union_store(std::vector<std::string>&& keys)
399399
{
400400
return 0;
401401
}
@@ -410,7 +410,7 @@ namespace cpp_redis {
410410
return false;
411411
}
412412

413-
virtual RESULTS_TYPE set_diff(KEYS&& keys)
413+
virtual RESULTS_TYPE set_diff(std::vector<std::string>&& keys)
414414
{
415415
return {};
416416
}
@@ -424,12 +424,12 @@ namespace cpp_redis {
424424
return {};
425425
}
426426

427-
virtual int set_diff_store(KEYS&& keys)
427+
virtual int set_diff_store(std::vector<std::string>&& keys)
428428
{
429429
return -1;
430430
}
431431

432-
virtual int zset_add(KEYS&& keys)
432+
virtual int zset_add(std::vector<std::string>&& keys)
433433
{
434434
return -1;
435435
}
@@ -484,7 +484,7 @@ namespace cpp_redis {
484484
return -1;
485485
}
486486

487-
virtual bool zset_rem(KEYS&& keys)
487+
virtual bool zset_rem(std::vector<std::string>&& keys)
488488
{
489489
return false;
490490
}
@@ -513,12 +513,12 @@ namespace cpp_redis {
513513
return 0;
514514
}
515515

516-
virtual int zset_union_store(KEYS&& keys,aggregate_mothod mothod)
516+
virtual int zset_union_store(std::vector<std::string>&& keys,aggregate_mothod mothod)
517517
{
518518
return -1;
519519
}
520520

521-
virtual int zset_inter_store(KEYS&& keys, aggregate_mothod mothod)
521+
virtual int zset_inter_store(std::vector<std::string>&& keys, aggregate_mothod mothod)
522522
{
523523
return -1;
524524
}
@@ -543,7 +543,7 @@ namespace cpp_redis {
543543
return "";
544544
}
545545

546-
virtual int hash_del(KEYS&& fields)
546+
virtual int hash_del(std::vector<std::string>&& fields)
547547
{
548548
return -1;
549549
}
@@ -568,12 +568,12 @@ namespace cpp_redis {
568568
return "";
569569
}
570570

571-
virtual bool hash_mset(KEYS&& keys)
571+
virtual bool hash_mset(std::vector<std::string>&& keys)
572572
{
573573
return false;
574574
}
575575

576-
virtual RESULTS_TYPE hash_mget(KEYS&& keys)
576+
virtual RESULTS_TYPE hash_mget(std::vector<std::string>&& keys)
577577
{
578578
return { {} };
579579
}

include/cppredis/cpp_define.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,6 @@ namespace cpp_redis {
106106
const std::string g_hash_incrby_float_cmd = "HINCRBYFLOAT";
107107
/*******************************************************************/
108108

109-
typedef std::string BYTES;
110-
typedef std::string KEY;
111-
typedef std::vector<KEY> KEYS;
112-
typedef std::vector<std::pair<KEY, BYTES> > PAIRS;//多个key一起发
113-
typedef PAIRS::value_type PAIR;
114-
typedef std::pair<int, BYTES> INT_VALUE;
115-
typedef std::vector<BYTES>VALUES;
116-
117109
enum status
118110
{
119111
unconnected_ = -1,

include/cppredis/cpp_hash_client.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ namespace cpp_redis
9696
return ((results[0] == g_nil) ? "" : results[0]);
9797
}
9898

99-
virtual int hash_del(KEYS&& fields)
99+
virtual int hash_del(std::vector<std::string>&& fields)
100100
{
101101
check_args();
102102

103-
std::string msg = request_->req_n_keys(request_->get_cmd(redis_cmd::hash_del), std::forward<KEYS>(fields));
103+
std::string msg = request_->req_n_keys(request_->get_cmd(redis_cmd::hash_del), std::forward<std::vector<std::string>>(fields));
104104

105105
socket_->send_msg(std::move(msg));
106106

@@ -203,9 +203,9 @@ namespace cpp_redis
203203
}
204204

205205

206-
virtual bool hash_mset(KEYS&& keys)
206+
virtual bool hash_mset(std::vector<std::string>&& keys)
207207
{
208-
std::string msg = request_->req_n_keys(request_->get_cmd(redis_cmd::hash_mset), std::forward<KEYS>(keys));
208+
std::string msg = request_->req_n_keys(request_->get_cmd(redis_cmd::hash_mset), std::forward<std::vector<std::string>>(keys));
209209
socket_->send_msg(std::move(msg));
210210

211211
const auto res = socket_->get_responese();
@@ -217,9 +217,9 @@ namespace cpp_redis
217217
return true;
218218
}
219219

220-
virtual RESULTS_TYPE hash_mget(KEYS&& keys)
220+
virtual RESULTS_TYPE hash_mget(std::vector<std::string>&& keys)
221221
{
222-
std::string msg = request_->req_n_keys(request_->get_cmd(redis_cmd::hash_mget), std::forward<KEYS>(keys));
222+
std::string msg = request_->req_n_keys(request_->get_cmd(redis_cmd::hash_mget), std::forward<std::vector<std::string>>(keys));
223223
socket_->send_msg(std::move(msg));
224224

225225
const auto res = socket_->get_responese();

include/cppredis/cpp_redis_request.hpp

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ namespace cpp_redis {
310310
{
311311
auto tp = std::make_tuple<Args...>(std::forward<Args>(key)...);
312312

313-
KEYS cmds;
313+
std::vector<std::string> cmds;
314314
cpp_redis::unit::for_each_tuple_front(tp, [this, &cmds](std::string str, const int& index) {
315315
cmds.push_back(std::move(str));
316316
});
@@ -319,76 +319,48 @@ namespace cpp_redis {
319319
return build_respone(std::move(command), std::move(cmds));
320320
}
321321

322-
std::string req_n_keys(std::string&& command, KEYS&& keys)
322+
std::string req_n_keys(std::string&& command, std::vector<std::string>&& keys)
323323
{
324-
return build_respone(std::move(command), std::forward<KEYS>(keys));
324+
return build_respone(std::move(command), std::forward<std::vector<std::string>>(keys));
325325
}
326-
327-
template<typename T>
328-
std::string build_respone(std::string&& command, T&& cmds)
326+
private:
327+
std::string build_respone(std::string&& command, std::vector<std::string>&& cmds)
329328
{
330-
auto key_cmds = std::move(cmds);
331-
BYTES v;
332-
add_number(get_commands(key_cmds), v, '*');
333-
add_value_with_size(command, v);
334-
335-
for (auto i = key_cmds.begin(); i != key_cmds.end(); ++i) {
336-
auto& p = *i;
337-
338-
add_pair(p, v);
329+
std::vector<std::string> key_cmds = std::move(cmds);
330+
size_t cmd_size = cmds.size();
331+
332+
std::string v;
333+
add_number(cmd_size+1, v, '*');
334+
add_value_with_size(std::forward<std::string>(command), v);
335+
336+
for (size_t index =0;index < cmd_size;++index){
337+
add_pair(std::move(key_cmds[index]), v);
339338
}
340339

341340
return std::move(v);
342341
}
343342

344-
template<typename T>
345-
int get_commands(const T& cmds)
346-
{
347-
return cmds.size() + 1;
348-
}
349-
350-
int get_commands(const PAIRS& cmds)
351-
{
352-
return cmds.size() * 2 + 1;
353-
}
354-
355-
template <class T>
356-
void add_value(T* x, size_t sz, BYTES& v)
357-
{
358-
std::copy(x, x + sz, std::back_inserter(v));
359-
std::copy(g_crlf.begin(), g_crlf.begin() + 2, std::back_inserter(v));
360-
}
361-
362-
template<class T>
363-
void add_value(T& s, BYTES& v)
343+
void add_value(std::string&& s, std::string& v)
364344
{
365-
add_value(&s[0], s.size(), v);
345+
std::string str = std::move(s);
346+
v.append(str).append(g_crlf);
366347
}
367348

368-
void add_number(int k, BYTES& v, char start = '$')
349+
void add_number(int k, std::string& v, char start = '$')
369350
{
370-
std::string n = unit::int_to_string(k);
371351
v.push_back(start);
372-
add_value(n, v);
352+
add_value(unit::int_to_string(k), v);
373353
}
374354

375-
template<class T>
376-
void add_value_with_size(T& s, BYTES& v)
355+
void add_value_with_size(std::string&& s, std::string& v)
377356
{
378357
add_number(s.size(), v);
379-
add_value(&s[0], s.size(), v);
380-
}
381-
382-
void add_pair(PAIR& p, BYTES& v)
383-
{
384-
add_value_with_size(p.first, v);
385-
add_value_with_size(p.second, v);
358+
add_value(std::forward<std::string>(s),v);
386359
}
387360

388-
template <class T>
389-
void add_pair(T& p, BYTES& v)
361+
void add_pair(std::string&& p, std::string& v)
390362
{
391-
add_value_with_size(p, v);
363+
add_value_with_size(std::forward<std::string>(p), v);
392364
}
393365
};
394366
}//cpp_redis

include/cppredis/cpp_redis_string.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,11 @@ namespace cpp_redis {
287287
return ((!results.empty()) ? results[0] : "");
288288
}
289289

290-
virtual VALUES multi_get_keys(KEYS &&keys)
290+
virtual std::vector<std::string> multi_get_keys(std::vector<std::string>&&keys)
291291
{
292292
check_args();
293293

294-
VALUES values;
295-
std::string msg = request_->req_n_keys(request_->get_cmd(cpp_redis::mget), std::forward<KEYS>(keys));
294+
std::string msg = request_->req_n_keys(request_->get_cmd(cpp_redis::mget), std::forward<std::vector<std::string>>(keys));
296295
socket_->send_msg(std::move(msg));
297296
const auto res = socket_->get_responese();
298297

@@ -304,10 +303,10 @@ namespace cpp_redis {
304303
}
305304

306305
/****************此接口需要传key,value,key,value....*************************/
307-
virtual bool multi_set_keys(KEYS && keys)
306+
virtual bool multi_set_keys(std::vector<std::string>&& keys)
308307
{
309308
check_args();
310-
std::string msg = request_->req_n_keys(request_->get_cmd(cpp_redis::mset), std::forward<KEYS>(keys));
309+
std::string msg = request_->req_n_keys(request_->get_cmd(cpp_redis::mset), std::forward<std::vector<std::string>>(keys));
311310
socket_->send_msg(std::move(msg));
312311
const auto res = socket_->get_responese();
313312
if (res->get_result_code() != status::status_) {
@@ -319,11 +318,11 @@ namespace cpp_redis {
319318

320319
/****************此接口需要传key,value,key,value....*************************/
321320
//当所有 key 都成功设置,返回 1 。 如果所有给定 key 都设置失败(至少有一个 key 已经存在),那么返回 0,表示失败
322-
virtual int multi_set_if_not_set(KEYS&&keys)
321+
virtual int multi_set_if_not_set(std::vector<std::string>&&keys)
323322
{
324323
check_args();
325324

326-
std::string msg = request_->req_n_keys(request_->get_cmd(cpp_redis::msetnx), std::forward<KEYS>(keys));
325+
std::string msg = request_->req_n_keys(request_->get_cmd(cpp_redis::msetnx), std::forward<std::vector<std::string>>(keys));
327326
socket_->send_msg(std::move(msg));
328327
const auto res = socket_->get_responese();
329328
if (res->get_result_code() != status::int_result_) {

0 commit comments

Comments
 (0)