Skip to content

Commit 09e8ca9

Browse files
author
liuh-80
committed
Improve code
1 parent 63cd5b6 commit 09e8ca9

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

common/dbconnector.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include "common/dbconnector.h"
1212
#include "common/redisreply.h"
13-
#include "common/redisapi.h"
13+
//#include "common/redisapi.h"
1414
#include "common/redispipeline.h"
1515
#include "common/pubsub.h"
1616

@@ -884,9 +884,7 @@ void DBConnector::hmset(const std::unordered_map<std::string, std::vector<std::p
884884
RedisPipeline pipe(this);
885885
for (auto& hash : multiHash)
886886
{
887-
RedisCommand hset;
888-
hset.formatHSET(hash.first, hash.second.begin(), hash.second.end());
889-
pipe.push(hset, REDIS_REPLY_INTEGER);
887+
pipe.pushHset(hash.first, hash.second.begin(), hash.second.end());
890888
}
891889

892890
pipe.flush();
@@ -899,9 +897,7 @@ void DBConnector::del(const std::vector<std::string>& keys)
899897
RedisPipeline pipe(this);
900898
for (auto& key : keys)
901899
{
902-
RedisCommand del;
903-
del.formatDEL(key);
904-
pipe.push(del, REDIS_REPLY_INTEGER);
900+
pipe.pushDel(key);
905901
}
906902

907903
pipe.flush();

common/redispipeline.h

+20
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ class RedisPipeline {
6262
return r.release();
6363
}
6464

65+
redisReply *pushHset(const std::string& key, const std::map<std::string, std::string> &values)
66+
{
67+
return pushHset(key, values.begin(), values.end());
68+
}
69+
70+
template<typename InputIterator>
71+
redisReply *pushHset(const std::string& key, const InputIterator& begin, const InputIterator& end)
72+
{
73+
RedisCommand hset;
74+
hset.formatHSET(key, begin, end);
75+
return push(hset, REDIS_REPLY_INTEGER);
76+
}
77+
78+
redisReply *pushDel(const std::string& key)
79+
{
80+
RedisCommand del;
81+
del.formatDEL(key);
82+
return push(del, REDIS_REPLY_INTEGER);
83+
}
84+
6585
std::string loadRedisScript(const std::string& script)
6686
{
6787
RedisCommand loadcmd;

0 commit comments

Comments
 (0)