@@ -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
0 commit comments