From f65bc6575e96917d57498f7cecbee83ae253595d Mon Sep 17 00:00:00 2001 From: SunnyQjm Date: Tue, 2 Jun 2020 09:53:26 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=B7=BB=E5=8A=A0=E9=80=9A=E4=BF=A1?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=AE=9A=E4=B9=89=EF=BC=8C=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=92=8C=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 10 +- Server.cpp | 98 +++++++++++++++++++ Server.h | 35 +++++++ main.cpp | 36 +++++-- .../AddOrUpdateCertificateRequestMessage.h | 65 ++++++++++++ message/BaseRequestMessage.h | 67 +++++++++++++ message/ExistsCertificateRequestMessage.h | 47 +++++++++ message/GetLifetimeRequestMessage.h | 51 ++++++++++ message/RemoveCertificateRequestMessage.h | 50 ++++++++++ utils/JsonCppUtil.cpp | 37 +++++++ utils/JsonCppUtil.h | 34 +++++++ utils/NDNCertificationUtil.cpp | 21 +++- utils/NDNCertificationUtil.h | 21 +++- utils/RedisUtil.cpp | 2 +- 14 files changed, 560 insertions(+), 14 deletions(-) create mode 100644 Server.cpp create mode 100644 Server.h create mode 100644 message/AddOrUpdateCertificateRequestMessage.h create mode 100644 message/BaseRequestMessage.h create mode 100644 message/ExistsCertificateRequestMessage.h create mode 100644 message/GetLifetimeRequestMessage.h create mode 100644 message/RemoveCertificateRequestMessage.h create mode 100644 utils/JsonCppUtil.cpp create mode 100644 utils/JsonCppUtil.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 465b98a..5d28797 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,14 @@ project(MIRCertificationManager) set(CMAKE_CXX_STANDARD 14) -add_executable(MIRCertificationManager main.cpp utils/RedisUtil.cpp) -target_link_libraries(MIRCertificationManager hiredis) +add_executable(MIRCertificationManager main.cpp + utils/RedisUtil.cpp + utils/RedisUtil.cpp + utils/NDNCertificationUtil.cpp + utils/JsonCppUtil.cpp + Server.cpp + ) +target_link_libraries(MIRCertificationManager ndn-cxx boost_system hiredis jsoncpp) add_executable(installCertificate installCertificate.cpp utils/FileUtils.cpp diff --git a/Server.cpp b/Server.cpp new file mode 100644 index 0000000..8939b38 --- /dev/null +++ b/Server.cpp @@ -0,0 +1,98 @@ +// +// Created by mingj on 2020/5/31. +// + +#include "Server.h" +#include +#include "utils/JsonCppUtil.h" +#include "message/BaseRequestMessage.h" +#include "message/AddOrUpdateCertificateRequestMessage.h" +#include "message/RemoveCertificateRequestMessage.h" +#include "message/GetLifetimeRequestMessage.h" +#include "message/ExistsCertificateRequestMessage.h" + + +Server::Server(std::string prefix) : + registerPrefix(std::move(prefix)) { + +} + +void Server::run() { + // 连接到本地的redis服务 + ndnCertificationUtil.connect(); + face.setInterestFilter(this->registerPrefix, + [this](const InterestFilter &filter, const Interest &interest) { + this->onInterest(filter, interest); + }, + RegisterPrefixSuccessCallback(), + [this](const Name &prefix, const std::string &reason) { + this->onRegisterFailed(prefix, reason); + } + ); + face.processEvents(); +} + +void Server::onInterest(const InterestFilter &filter, const Interest &interest) { + if (interest.getApplicationParameters().value_size() <= 0) + return; + std::string params((char *) (interest.getApplicationParameters().value()), + interest.getApplicationParameters().value_size()); + JsonCppUtil jsonCppUtil(params); + Data data(interest.getName()); + Json::Value root; + int resCode; + long longResult; + AddOrUpdateCertificateRequestMessage addOrUpdateCertificateRequestMessage; + RemoveCertificateRequestMessage removeCertificateRequestMessage; + GetLifetimeRequestMessage getLifetimeRequestMessage; + ExistsCertificateRequestMessage existsCertificateRequestMessage; + switch (jsonCppUtil.getInt("code")) { + case BaseRequestMessage::ADD_OR_UPDATE_CERTIFICATE: // 下发或更新证书 + addOrUpdateCertificateRequestMessage.parse(params); + root["code"] = ndnCertificationUtil.installCert(addOrUpdateCertificateRequestMessage.getCertStr(), + addOrUpdateCertificateRequestMessage.getLifetime(), + addOrUpdateCertificateRequestMessage.isForceUpdate()); + root["errMsg"] = addOrUpdateCertificateRequestMessage.getErrorMessage(root["code"].asInt()); + break; + case BaseRequestMessage::REMOVE_CERTIFICATE: // 撤销证书 + removeCertificateRequestMessage.parse(params); + resCode = ndnCertificationUtil.uninstallCert(removeCertificateRequestMessage.getCertStr()); + if (resCode >= 0) { + resCode = 0; + } else { + resCode = resCode; + } + root["code"] = resCode; + root["errMsg"] = removeCertificateRequestMessage.getErrorMessage(resCode); + break; + case BaseRequestMessage::GET_CERTIFICATE_LIFETIME: // 获取证书的生存期 + getLifetimeRequestMessage.parse(params); + longResult = ndnCertificationUtil.getCertLifetime(getLifetimeRequestMessage.getCertStr()); + root["data"] = (long long int) longResult; + if (longResult >= 0) { + resCode = 0; + } else { + resCode = (int) longResult; + } + root["code"] = resCode; + root["errMsg"] = getLifetimeRequestMessage.getErrorMessage(resCode); + break; + case BaseRequestMessage::EXISTS_CERTIFICATE: // 证书是否存在 + existsCertificateRequestMessage.parse(params); + if (ndnCertificationUtil.exists(existsCertificateRequestMessage.getCertStr())) { + root["code"] = 0; + } else { + root["code"] = -1; + } + root["errMsg"] = existsCertificateRequestMessage.getErrorMessage(root["code"].asInt()); + break; + default: + std::cerr << "未能处理的请求:" << endl << params << endl; + break; + } +} + +void Server::onRegisterFailed(const Name &prefix, const std::string &reason) { + +} + diff --git a/Server.h b/Server.h new file mode 100644 index 0000000..ed4aa55 --- /dev/null +++ b/Server.h @@ -0,0 +1,35 @@ +// +// Created by mingj on 2020/5/31. +// + +#ifndef MIRCERTIFICATIONMANAGER_SERVER_H +#define MIRCERTIFICATIONMANAGER_SERVER_H + +#include +#include +#include +#include "utils/NDNCertificationUtil.h" + +using namespace ndn; + +class Server { +public: + explicit + Server(std::string prefix = "/localmanager/mircertification"); + + void run(); + +private: + void onInterest(const InterestFilter &filter, const Interest &interest); + + void onRegisterFailed(const Name &prefix, const std::string &reason); + +private: + Face face; + KeyChain keyChain; + NDNCertificationUtil ndnCertificationUtil; + std::string registerPrefix; +}; + + +#endif //MIRCERTIFICATIONMANAGER_SERVER_H diff --git a/main.cpp b/main.cpp index 4a37591..fd76c55 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,6 @@ #include #include "utils/RedisUtil.h" +#include "Server.h" /** * @@ -12,14 +13,31 @@ 4. 把退出登录的功能也做一做。即从redis中删除证书。加载证书和删除证书的代码不写到NFD中,应单独开发。 * @return */ + +using namespace std; + int main() { - RedisUtil redisUtil; - redisUtil.connect("127.0.0.1", 6379); - std::cout << redisUtil.set("test", "1234") << std::endl; - auto result = redisUtil.get("test1"); - std::cout << result << std::endl; - std::cout << "exists: " << redisUtil.exist("test") << std::endl; - redisUtil.del("test"); - std::cout << "exists: " << redisUtil.exist("test") << std::endl; - return 0; + + Server server; + server.run(); + +// AddOrUpdateCertificateRequestMessage addOrUpdateCertificateRequestMessage; +// addOrUpdateCertificateRequestMessage.parse("{\n" +// "\"code\": 1,\n" +// "\"data\": {\n" +// "\"certStr\": \"证书的base64编码字符串\",\n" +// "\"lifetime\": 1000,\n" +// "\"forceUpdate\": false\n" +// "}\n" +// "}"); +// cout << addOrUpdateCertificateRequestMessage.getCertStr() << endl; +// RedisUtil redisUtil; +// redisUtil.connect("127.0.0.1", 6379); +// std::cout << redisUtil.set("test", "1234") << std::endl; +// auto result = redisUtil.get("test1"); +// std::cout << result << std::endl; +// std::cout << "exists: " << redisUtil.exist("test") << std::endl; +// redisUtil.del("test"); +// std::cout << "exists: " << redisUtil.exist("test") << std::endl; +// return 0; } diff --git a/message/AddOrUpdateCertificateRequestMessage.h b/message/AddOrUpdateCertificateRequestMessage.h new file mode 100644 index 0000000..c4e3aa1 --- /dev/null +++ b/message/AddOrUpdateCertificateRequestMessage.h @@ -0,0 +1,65 @@ +// +// Created by mingj on 2020/5/31. +// + +#ifndef MIRCERTIFICATIONMANAGER_ADDORUPDATECERTIFICATEREQUESTMESSAGE_H +#define MIRCERTIFICATIONMANAGER_ADDORUPDATECERTIFICATEREQUESTMESSAGE_H + +#include "BaseRequestMessage.h" + + +class AddOrUpdateCertificateRequestMessage : public BaseRequestMessage { +public: + struct AddOrUpdateCertificateRequestData { + std::string certStr = ""; + long lifetime = -1; + bool forceUpdate = false; + }; + + std::string getErrorMessage(int responseCode) override { + switch (responseCode) { + case 0: + return ""; + case -1: + return "证书无效"; + case -2: + return "存在同名证书,且未覆盖"; + default: + return "未知错误"; + } + } + + BaseRequestMessage *parse(const std::string &jsonStr) override { + Json::Reader reader; + Json::Value root; + reader.parse(jsonStr, root); + + this->code = code; + int code = root["code"].asInt(); + if (code != 1) + return this; + addOrUpdateCertificateRequestData.certStr = root["data"]["certStr"].asString(); + addOrUpdateCertificateRequestData.lifetime = root["data"]["lifetime"].asUInt64(); + addOrUpdateCertificateRequestData.forceUpdate = root["data"]["forceUpdate"].asBool(); + return this; + } + + + std::string getCertStr() const { + return addOrUpdateCertificateRequestData.certStr; + } + + long getLifetime() const { + return addOrUpdateCertificateRequestData.lifetime; + } + + bool isForceUpdate() const { + return addOrUpdateCertificateRequestData.forceUpdate; + } + +private: + AddOrUpdateCertificateRequestData addOrUpdateCertificateRequestData; +}; + + +#endif //MIRCERTIFICATIONMANAGER_ADDORUPDATECERTIFICATEREQUESTMESSAGE_H diff --git a/message/BaseRequestMessage.h b/message/BaseRequestMessage.h new file mode 100644 index 0000000..fafb4d1 --- /dev/null +++ b/message/BaseRequestMessage.h @@ -0,0 +1,67 @@ +// +// Created by mingj on 2020/5/31. +// + +#ifndef MIRCERTIFICATIONMANAGER_BASEREQUESTMESSAGE_H +#define MIRCERTIFICATIONMANAGER_BASEREQUESTMESSAGE_H + +#include +#include +#include + +class BaseRequestMessage { +public: + + static const int ADD_OR_UPDATE_CERTIFICATE; + static const int REMOVE_CERTIFICATE; + static const int GET_CERTIFICATE_LIFETIME; + static const int EXISTS_CERTIFICATE; + + int getCode() const { + return code; + } + + virtual BaseRequestMessage *parse(const std::string &jsonStr) {}; + + virtual std::string getErrorMessage(int responseCode) {}; + +// static BaseRequestMessage parse(const std::string &jsonStr) { +// Json::Reader reader; +// Json::Value root; +// reader.parse(jsonStr, root); +// +// int code = root["code"].asInt(); +// switch (code) { +// case 1: +// AddOrUpdateCertificateRequestData addOrUpdateCertificateRequestData; +// addOrUpdateCertificateRequestData.certStr = root["data"]["certStr"].asString(); +// addOrUpdateCertificateRequestData.lifetime = root["data"]["lifetime"].asUInt64(); +// addOrUpdateCertificateRequestData.forceUpdate = root["data"]["forceUpdate"].asBool(); +// return BaseRequestMessage(code, AddOrUpdateCertificateRequestData()); +// case 2: +// RemoveCertificateRequestData removeCertificateRequestData; +// removeCertificateRequestData.certStr = root["data"]["certStr"].asString(); +// return BaseRequestMessage(code, removeCertificateRequestData); +// case 3: +// GetCertificateLifetimeRequestData getCertificateLifetimeRequestData; +// getCertificateLifetimeRequestData.certStr = root["data"]["certStr"].asString(); +// return BaseRequestMessage(code, getCertificateLifetimeRequestData); +// case 4: +// ExistsCertificateRequestData existsCertificateRequestData; +// existsCertificateRequestData.certStr = root["data"]["certStr"].asString(); +// return BaseRequestMessage(code, existsCertificateRequestData); +// default: +// return BaseRequestMessage(code, ""); +// } +// } + +protected: + int code{0}; +}; + +const int BaseRequestMessage::ADD_OR_UPDATE_CERTIFICATE = 1; +const int BaseRequestMessage::REMOVE_CERTIFICATE = 2; +const int BaseRequestMessage::GET_CERTIFICATE_LIFETIME = 3; +const int BaseRequestMessage::EXISTS_CERTIFICATE = 4; + +#endif //MIRCERTIFICATIONMANAGER_BASEREQUESTMESSAGE_H diff --git a/message/ExistsCertificateRequestMessage.h b/message/ExistsCertificateRequestMessage.h new file mode 100644 index 0000000..3f390db --- /dev/null +++ b/message/ExistsCertificateRequestMessage.h @@ -0,0 +1,47 @@ +// +// Created by mingj on 2020/6/2. +// + +#ifndef MIRCERTIFICATIONMANAGER_EXISTSCERTIFICATEREQUESTMESSAGE_H +#define MIRCERTIFICATIONMANAGER_EXISTSCERTIFICATEREQUESTMESSAGE_H + +#include "BaseRequestMessage.h" + +class ExistsCertificateRequestMessage : BaseRequestMessage { +public: + struct ExistsCertificateRequestData { + std::string certStr = ""; + }; + + std::string getErrorMessage(int responseCode) override { + switch (responseCode) { + case 0: + return ""; + case -1: + return "没有对应的条目"; + default: + return "未知错误"; + } + } + + BaseRequestMessage * parse(const std::string &jsonStr) override { + Json::Reader reader; + Json::Value root; + reader.parse(jsonStr, root); + + this->code = code; + int code = root["code"].asInt(); + if (code != 1) + return this; + existsCertificateRequestData.certStr = root["data"]["certStr"].asString(); + return this; + } + + std::string getCertStr() const { + return existsCertificateRequestData.certStr; + } + +private: + ExistsCertificateRequestData existsCertificateRequestData; +}; +#endif //MIRCERTIFICATIONMANAGER_EXISTSCERTIFICATEREQUESTMESSAGE_H diff --git a/message/GetLifetimeRequestMessage.h b/message/GetLifetimeRequestMessage.h new file mode 100644 index 0000000..49f2c04 --- /dev/null +++ b/message/GetLifetimeRequestMessage.h @@ -0,0 +1,51 @@ +// +// Created by mingj on 2020/6/2. +// + +#ifndef MIRCERTIFICATIONMANAGER_GETLIFETIMEREQUESTMESSAGE_H +#define MIRCERTIFICATIONMANAGER_GETLIFETIMEREQUESTMESSAGE_H + +#include "BaseRequestMessage.h" + +class GetLifetimeRequestMessage : BaseRequestMessage { +public: + struct GetLifetimeRequestData { + std::string certStr = ""; + }; + + std::string getErrorMessage(int responseCode) override { + if (responseCode > 0) { + return ""; + } + switch (responseCode) { + case 0: + return ""; + case -2: + return "没有对应的条目"; + default: + return "未知错误"; + } + } + + BaseRequestMessage *parse(const std::string &jsonStr) override { + Json::Reader reader; + Json::Value root; + reader.parse(jsonStr, root); + + this->code = code; + int code = root["code"].asInt(); + if (code != 1) + return this; + getLifetimeRequestData.certStr = root["data"]["certStr"].asString(); + return this; + } + + std::string getCertStr() const { + return getLifetimeRequestData.certStr; + } + +private: + GetLifetimeRequestData getLifetimeRequestData; +}; + +#endif //MIRCERTIFICATIONMANAGER_GETLIFETIMEREQUESTMESSAGE_H \ No newline at end of file diff --git a/message/RemoveCertificateRequestMessage.h b/message/RemoveCertificateRequestMessage.h new file mode 100644 index 0000000..e735d72 --- /dev/null +++ b/message/RemoveCertificateRequestMessage.h @@ -0,0 +1,50 @@ +// +// Created by mingj on 2020/6/2. +// + +#ifndef MIRCERTIFICATIONMANAGER_REMOVECERTIFICATEREQUESTMESSAGE_H +#define MIRCERTIFICATIONMANAGER_REMOVECERTIFICATEREQUESTMESSAGE_H + +#include "BaseRequestMessage.h" + +class RemoveCertificateRequestMessage : BaseRequestMessage { +public: + struct RemoveCertificateRequestData { + std::string certStr = ""; + }; + + std::string getErrorMessage(int responseCode) override { + switch (responseCode) { + case 0: + return ""; + case -1: + return "证书无效"; + case -2: + return "没有对应的条目"; + default: + return "未知错误"; + } + } + + BaseRequestMessage * parse(const std::string &jsonStr) override { + Json::Reader reader; + Json::Value root; + reader.parse(jsonStr, root); + + this->code = code; + int code = root["code"].asInt(); + if (code != 1) + return this; + removeCertificateRequestData.certStr = root["data"]["certStr"].asString(); + return this; + } + + std::string getCertStr() const { + return removeCertificateRequestData.certStr; + } + +private: + RemoveCertificateRequestData removeCertificateRequestData; +}; + +#endif //MIRCERTIFICATIONMANAGER_REMOVECERTIFICATEREQUESTMESSAGE_H diff --git a/utils/JsonCppUtil.cpp b/utils/JsonCppUtil.cpp new file mode 100644 index 0000000..c4fbc7d --- /dev/null +++ b/utils/JsonCppUtil.cpp @@ -0,0 +1,37 @@ +// +// Created by mingj on 18-12-22. +// + +#include "JsonCppUtil.h" + +JsonCppUtil::JsonCppUtil(const string &jsonStr) { + Json::Reader reader; + + //将根节点解析到root当中 + reader.parse(jsonStr, this->root); +} + +string JsonCppUtil::getString(const string &key) { + + return root[key].asString(); +} + +int JsonCppUtil::getInt(const string &key) { + return root[key].asInt(); +} + +unsigned long long JsonCppUtil::getull(const string &key) { + return root[key].asUInt64(); +} + +bool JsonCppUtil::getBool(const string &key) { + return root[key].asBool(); +} + +double JsonCppUtil::getDouble(const string &key) { + return root[key].asDouble(); +} + +Json::Value JsonCppUtil::get(const string &key) { + return root[key]; +} diff --git a/utils/JsonCppUtil.h b/utils/JsonCppUtil.h new file mode 100644 index 0000000..936b26f --- /dev/null +++ b/utils/JsonCppUtil.h @@ -0,0 +1,34 @@ +// +// Created by mingj on 18-12-22. +// +#ifndef IP_NDN_STACK_CPP_JSONCPPHELPER_H +#define IP_NDN_STACK_CPP_JSONCPPHELPER_H + +#include +#include +#include + +using namespace std; + +class JsonCppUtil { +public: + explicit JsonCppUtil(const string &jsonStr); + + string getString(const string &key); + + int getInt(const string &key); + + unsigned long long getull(const string &key); + + bool getBool(const string &key); + + double getDouble(const string &key); + + Json::Value get(const string &key); + +private: + Json::Value root; +}; + + +#endif //IP_NDN_STACK_CPP_JSONCPPHELPER_H diff --git a/utils/NDNCertificationUtil.cpp b/utils/NDNCertificationUtil.cpp index a1e25d1..85f8118 100644 --- a/utils/NDNCertificationUtil.cpp +++ b/utils/NDNCertificationUtil.cpp @@ -45,7 +45,7 @@ bool NDNCertificationUtil::connect(const std::string &host, int port) { * -1 -> 证书无效 * -2 -> 已经存在 */ -int NDNCertificationUtil::installCert(const std::string &certStr, bool forceUpdate) { +int NDNCertificationUtil::installCert(const std::string &certStr, long lifetime, bool forceUpdate) { // 首先验证证书是否有效 if (!isValidBlock(certStr)) return -1; @@ -56,6 +56,7 @@ int NDNCertificationUtil::installCert(const std::string &certStr, bool forceUpda if (!forceUpdate && redisUtil.exist(cert.getName().toUri()) > 0) { return -2; } + redisUtil.setLifeTime(cert.getName().toUri(), lifetime); return redisUtil.set(cert.getName().toUri(), certStr) == 0; } @@ -145,3 +146,21 @@ bool NDNCertificationUtil::verifyData(const ndn::Data &data) { auto result = ndn::security::verifySignature(data, cert); return result; } + +/** + * 获取证书剩余存活时间,单位为毫秒; + * + * + * @param key + * @return + * -2 => 返回-2表示key对应的条目不存在(可能是本来就没有这个条目,或者本来有一个条目,但是因为设置了存活期,其存活期已到,被移除了) + * -1 => 返回-1表示key对应的条目存在,但是没有设置过存活期,是持久保存的 + * >= 0 => 返回大于等于0的值表示key对应的条目存在,且其剩余的存活时间为返回的值,单位为毫秒 + */ +long NDNCertificationUtil::getCertLifetime(const std::string &key) { + return redisUtil.getRemainingTime(key); +} + +bool NDNCertificationUtil::exists(const std::string &key) { + return redisUtil.exist(key) > 0; +} diff --git a/utils/NDNCertificationUtil.h b/utils/NDNCertificationUtil.h index 456f5d6..5a57091 100644 --- a/utils/NDNCertificationUtil.h +++ b/utils/NDNCertificationUtil.h @@ -47,7 +47,7 @@ public: * -1 -> 证书无效 * -2 -> 已经存在 */ - int installCert(const std::string &certStr, bool forceUpdate = false); + int installCert(const std::string &certStr, long lifetime = -1, bool forceUpdate = false); /** * 卸载证书操作 @@ -68,6 +68,25 @@ public: */ std::string getCertStrByKeyName(const std::string &keyName); + /** + * 获取证书剩余存活时间,单位为毫秒; + * + * + * @param key + * @return + * -2 => 返回-2表示key对应的条目不存在(可能是本来就没有这个条目,或者本来有一个条目,但是因为设置了存活期,其存活期已到,被移除了) + * -1 => 返回-1表示key对应的条目存在,但是没有设置过存活期,是持久保存的 + * >= 0 => 返回大于等于0的值表示key对应的条目存在,且其剩余的存活时间为返回的值,单位为毫秒 + */ + long getCertLifetime(const std::string &key); + + /** + * 判断某个证书是否存在 + * @param key + * @return 如果存在则返回大于0的值,典型值为1 + */ + bool exists(const std::string &key); + /** * 验证兴趣包签名是否有效 * @param interest diff --git a/utils/RedisUtil.cpp b/utils/RedisUtil.cpp index cf7476a..1da3d27 100644 --- a/utils/RedisUtil.cpp +++ b/utils/RedisUtil.cpp @@ -99,7 +99,7 @@ int RedisUtil::setLifeTime(const std::string &key, long lifetime) { * @param key * @return * -2 => 返回-2表示key对应的条目不存在(可能是本来就没有这个条目,或者本来有一个条目,但是因为设置了存活期,其存活期已到,被移除了) - * -1 => 返回-1表示key对应的条目存在,但是没有设置过存活期,是持久保存的 + * -1 => 返回-1表示key对应的条目存在,但是没有设置过存活期,是持久保存的 * >= 0 => 返回大于等于0的值表示key对应的条目存在,且其剩余的存活时间为返回的值,单位为毫秒 */ long RedisUtil::getRemainingTime(const std::string &key) {