|
10 | 10 |
|
11 | 11 | #include "common/dbconnector.h"
|
12 | 12 | #include "common/redisreply.h"
|
13 |
| -#include "common/redisapi.h" |
| 13 | +#include "common/redispipeline.h" |
14 | 14 | #include "common/pubsub.h"
|
15 | 15 |
|
16 | 16 | using json = nlohmann::json;
|
@@ -880,55 +880,28 @@ void DBConnector::hmset(const std::unordered_map<std::string, std::vector<std::p
|
880 | 880 | {
|
881 | 881 | SWSS_LOG_ENTER();
|
882 | 882 |
|
883 |
| - // make sure this will be object (not null) when multi hash is empty |
884 |
| - json j = json::object(); |
885 |
| - |
886 |
| - // pack multi hash to json (takes bout 70 ms for 10k to construct) |
887 |
| - for (const auto& kvp: multiHash) |
| 883 | + RedisPipeline pipe(this); |
| 884 | + for (auto& hash : multiHash) |
888 | 885 | {
|
889 |
| - json o; |
890 |
| - |
891 |
| - for (const auto &item: kvp.second) |
892 |
| - { |
893 |
| - o[std::get<0>(item)] = std::get<1>(item); |
894 |
| - } |
895 |
| - |
896 |
| - j[kvp.first] = o; |
| 886 | + RedisCommand hset; |
| 887 | + hset.formatHSET(hash.first, hash.second.begin(), hash.second.end()); |
| 888 | + pipe.push(hset, REDIS_REPLY_INTEGER); |
897 | 889 | }
|
898 | 890 |
|
899 |
| - std::string strJson = j.dump(); |
900 |
| - |
901 |
| - lazyLoadRedisScriptFile(this, "redis_multi.lua", m_shaRedisMulti); |
902 |
| - RedisCommand command; |
903 |
| - command.format( |
904 |
| - "EVALSHA %s 1 %s %s", |
905 |
| - m_shaRedisMulti.c_str(), |
906 |
| - strJson.c_str(), |
907 |
| - "mhset"); |
908 |
| - |
909 |
| - RedisReply r(this, command, REDIS_REPLY_NIL); |
| 891 | + pipe.flush(); |
910 | 892 | }
|
911 | 893 |
|
912 | 894 | void DBConnector::del(const std::vector<std::string>& keys)
|
913 | 895 | {
|
914 | 896 | SWSS_LOG_ENTER();
|
915 | 897 |
|
916 |
| - json j = json::array(); |
917 |
| - |
918 |
| - for (const auto& key: keys) |
| 898 | + RedisPipeline pipe(this); |
| 899 | + for (auto& key : keys) |
919 | 900 | {
|
920 |
| - j.push_back(key); |
| 901 | + RedisCommand del; |
| 902 | + del.formatDEL(key); |
| 903 | + pipe.push(del, REDIS_REPLY_INTEGER); |
921 | 904 | }
|
922 | 905 |
|
923 |
| - std::string strJson = j.dump(); |
924 |
| - |
925 |
| - lazyLoadRedisScriptFile(this, "redis_multi.lua", m_shaRedisMulti); |
926 |
| - RedisCommand command; |
927 |
| - command.format( |
928 |
| - "EVALSHA %s 1 %s %s", |
929 |
| - m_shaRedisMulti.c_str(), |
930 |
| - strJson.c_str(), |
931 |
| - "mdel"); |
932 |
| - |
933 |
| - RedisReply r(this, command, REDIS_REPLY_NIL); |
| 906 | + pipe.flush(); |
934 | 907 | }
|
0 commit comments