From aef3b080aea4afdea72fd54c5dd39e83ed9b6eb2 Mon Sep 17 00:00:00 2001 From: Ryan Joseph Date: Thu, 17 Aug 2023 04:34:40 +0000 Subject: [PATCH] Apply code formatting to library source --- Redis.cpp | 159 +++++++++++++++++++++++----------------------- Redis.h | 48 +++++++------- RedisInternal.cpp | 11 ++-- RedisInternal.h | 7 +- 4 files changed, 118 insertions(+), 107 deletions(-) diff --git a/Redis.cpp b/Redis.cpp index 4880358..7cdec00 100644 --- a/Redis.cpp +++ b/Redis.cpp @@ -103,7 +103,7 @@ std::vector Redis::lrange(const char *key, int start, int stop) { auto rv = RedisCommand("LRANGE", ArgList{key, String(start), String(stop)}).issue(conn); - if(rv->type() == RedisObject::Type::InternalError) + if (rv->type() == RedisObject::Type::InternalError) { std::vector r = std::vector(); String error_message = (String)(((RedisInternalError *)rv.get())->RESP()); @@ -113,8 +113,8 @@ std::vector Redis::lrange(const char *key, int start, int stop) else { return rv->type() == RedisObject::Type::Array - ? (std::vector)*((RedisArray *)rv.get()) - : std::vector(); + ? (std::vector)*((RedisArray *)rv.get()) + : std::vector(); } } @@ -181,26 +181,26 @@ String Redis::xadd(const char *key, const char *id, const char *field, TRCMD(String, "XADD", key, id, field, value); } -std::vector Redis::xautoclaim(const char *key, const char* group, - const char* consumer, unsigned int min_idle_time, const char *start, - unsigned int count, bool justid) +std::vector Redis::xautoclaim(const char *key, const char *group, + const char *consumer, unsigned int min_idle_time, const char *start, + unsigned int count, bool justid) { ArgList argList = ArgList{key, group, consumer, String(min_idle_time), start}; - if(count > 0) + if (count > 0) { argList.push_back("COUNT"); argList.push_back(String(count)); } - if(justid == true) + if (justid == true) { argList.push_back("JUSTID"); } auto rv = RedisCommand("XAUTOCLAIM", argList).issue(conn); - if(rv->type() == RedisObject::Type::InternalError) + if (rv->type() == RedisObject::Type::InternalError) { std::vector r = std::vector(); String error_message = (String)(((RedisInternalError *)rv.get())->RESP()); @@ -210,47 +210,47 @@ std::vector Redis::xautoclaim(const char *key, const char* group, else { return rv->type() == RedisObject::Type::Array - ? (std::vector)*((RedisArray *)rv.get()) - : std::vector(); + ? (std::vector)*((RedisArray *)rv.get()) + : std::vector(); } } std::vector Redis::xclaim(const char *key, const char *group, - const char *consumer, unsigned int min_idle_time, const char *id, - unsigned int idle_ms, unsigned int time_ms, unsigned int retrycount, - bool force, bool justid, const char *lastid) + const char *consumer, unsigned int min_idle_time, const char *id, + unsigned int idle_ms, unsigned int time_ms, unsigned int retrycount, + bool force, bool justid, const char *lastid) { ArgList argList = ArgList{key, group, consumer, String(min_idle_time), id}; - if(idle_ms > 0) + if (idle_ms > 0) { argList.push_back("IDLE"); argList.push_back(String(idle_ms)); } - if(time_ms > 0) + if (time_ms > 0) { argList.push_back("TIME"); argList.push_back(String(time_ms)); } - if(retrycount > 0) + if (retrycount > 0) { argList.push_back("RETRYCOUNT"); argList.push_back(String(retrycount)); } - if(force == true) + if (force == true) { argList.push_back("FORCE"); } - if(justid == true) + if (justid == true) { argList.push_back("JUSTID"); } - if(lastid != NULL && strlen(lastid) > 0) + if (lastid != NULL && strlen(lastid) > 0) { argList.push_back("LASTID"); argList.push_back(lastid); @@ -258,7 +258,7 @@ std::vector Redis::xclaim(const char *key, const char *group, auto rv = RedisCommand("XCLAIM", argList).issue(conn); - if(rv->type() == RedisObject::Type::InternalError) + if (rv->type() == RedisObject::Type::InternalError) { std::vector r = std::vector(); String error_message = (String)(((RedisInternalError *)rv.get())->RESP()); @@ -268,8 +268,8 @@ std::vector Redis::xclaim(const char *key, const char *group, else { return rv->type() == RedisObject::Type::Array - ? (std::vector)*((RedisArray *)rv.get()) - : std::vector(); + ? (std::vector)*((RedisArray *)rv.get()) + : std::vector(); } } @@ -281,7 +281,7 @@ int Redis::xdel(const char *key, const char *id) bool Redis::xgroup_create(const char *key, const char *group, const char *id, bool mkstream) { - if(mkstream) + if (mkstream) { TRCMD_EXPECTOK("XGROUP", "CREATE", key, group, id, "MKSTREAM"); } @@ -308,16 +308,16 @@ int Redis::xgroup_destroy(const char *key, const char *group) TRCMD(int, "XGROUP", "DESTROY", key, group); } -bool Redis::xgroup_setid(const char* key, const char *group, const char *id) +bool Redis::xgroup_setid(const char *key, const char *group, const char *id) { TRCMD_EXPECTOK("XGROUP", "SETID", key, group, id); } -std::vector Redis::xinfo_consumers(const char *key, const char* group) +std::vector Redis::xinfo_consumers(const char *key, const char *group) { auto rv = RedisCommand("XINFO", ArgList{"CONSUMERS", key, group}).issue(conn); - if(rv->type() == RedisObject::Type::InternalError) + if (rv->type() == RedisObject::Type::InternalError) { std::vector r = std::vector(); String error_message = (String)(((RedisInternalError *)rv.get())->RESP()); @@ -327,8 +327,8 @@ std::vector Redis::xinfo_consumers(const char *key, const char* group) else { return rv->type() == RedisObject::Type::Array - ? (std::vector)*((RedisArray *)rv.get()) - : std::vector(); + ? (std::vector)*((RedisArray *)rv.get()) + : std::vector(); } } @@ -336,7 +336,7 @@ std::vector Redis::xinfo_groups(const char *key) { auto rv = RedisCommand("XINFO", ArgList{"GROUPS", key}).issue(conn); - if(rv->type() == RedisObject::Type::InternalError) + if (rv->type() == RedisObject::Type::InternalError) { std::vector r = std::vector(); String error_message = (String)(((RedisInternalError *)rv.get())->RESP()); @@ -346,21 +346,21 @@ std::vector Redis::xinfo_groups(const char *key) else { return rv->type() == RedisObject::Type::Array - ? (std::vector)*((RedisArray *)rv.get()) - : std::vector(); + ? (std::vector)*((RedisArray *)rv.get()) + : std::vector(); } } std::vector Redis::xinfo_stream(const char *key, bool full, - unsigned int count) + unsigned int count) { ArgList argList = ArgList{"STREAM", key}; - if(full == true) + if (full == true) { argList.push_back("FULL"); - if(count > 0) + if (count > 0) { argList.push_back("COUNT"); argList.push_back(String(count)); @@ -369,7 +369,7 @@ std::vector Redis::xinfo_stream(const char *key, bool full, auto rv = RedisCommand("XINFO", argList).issue(conn); - if(rv->type() == RedisObject::Type::InternalError) + if (rv->type() == RedisObject::Type::InternalError) { std::vector r = std::vector(); String error_message = (String)(((RedisInternalError *)rv.get())->RESP()); @@ -379,8 +379,8 @@ std::vector Redis::xinfo_stream(const char *key, bool full, else { return rv->type() == RedisObject::Type::Array - ? (std::vector)*((RedisArray *)rv.get()) - : std::vector(); + ? (std::vector)*((RedisArray *)rv.get()) + : std::vector(); } } @@ -389,33 +389,33 @@ int Redis::xlen(const char *key) TRCMD(int, "XLEN", key); } -std::vector Redis::xpending(const char *key, const char* group, - unsigned int min_idle_time, const char *start, const char *end, - unsigned int count, const char *consumer) +std::vector Redis::xpending(const char *key, const char *group, + unsigned int min_idle_time, const char *start, const char *end, + unsigned int count, const char *consumer) { ArgList argList = ArgList{key, group}; - if(min_idle_time > 0) + if (min_idle_time > 0) { argList.push_back("IDLE"); argList.push_back(String(min_idle_time)); } - if(start != NULL && strlen(start) > 0 && end != NULL && strlen(end) > 0) + if (start != NULL && strlen(start) > 0 && end != NULL && strlen(end) > 0) { argList.push_back(start); argList.push_back(end); argList.push_back(String(count)); } - if(consumer != NULL && strlen(consumer) > 0) + if (consumer != NULL && strlen(consumer) > 0) { argList.push_back(consumer); } auto rv = RedisCommand("XPENDING", argList).issue(conn); - if(rv->type() == RedisObject::Type::InternalError) + if (rv->type() == RedisObject::Type::InternalError) { std::vector r = std::vector(); String error_message = (String)(((RedisInternalError *)rv.get())->RESP()); @@ -425,17 +425,17 @@ std::vector Redis::xpending(const char *key, const char* group, else { return rv->type() == RedisObject::Type::Array - ? (std::vector)*((RedisArray *)rv.get()) - : std::vector(); + ? (std::vector)*((RedisArray *)rv.get()) + : std::vector(); } } std::vector Redis::xrange(const char *key, const char *start, - const char *end, unsigned int count) + const char *end, unsigned int count) { ArgList argList = ArgList{key, start, end}; - if(count > 0) + if (count > 0) { argList.push_back("COUNT"); argList.push_back(String(count)); @@ -443,7 +443,7 @@ std::vector Redis::xrange(const char *key, const char *start, auto rv = RedisCommand("XRANGE", argList).issue(conn); - if(rv->type() == RedisObject::Type::InternalError) + if (rv->type() == RedisObject::Type::InternalError) { std::vector r = std::vector(); String error_message = (String)(((RedisInternalError *)rv.get())->RESP()); @@ -453,23 +453,23 @@ std::vector Redis::xrange(const char *key, const char *start, else { return rv->type() == RedisObject::Type::Array - ? (std::vector)*((RedisArray *)rv.get()) - : std::vector(); + ? (std::vector)*((RedisArray *)rv.get()) + : std::vector(); } } std::vector Redis::xread(unsigned int count, unsigned int block, - const char *key, const char *id) + const char *key, const char *id) { ArgList argList = std::vector(); - if(count > 0) + if (count > 0) { argList.push_back("COUNT"); argList.push_back(String(count)); } - if(block > 0) + if (block > 0) { argList.push_back("BLOCK"); argList.push_back(String(block)); @@ -481,7 +481,7 @@ std::vector Redis::xread(unsigned int count, unsigned int block, auto rv = RedisCommand("XREAD", argList).issue(conn); - if(rv->type() == RedisObject::Type::InternalError) + if (rv->type() == RedisObject::Type::InternalError) { std::vector r = std::vector(); String error_message = (String)(((RedisInternalError *)rv.get())->RESP()); @@ -491,35 +491,35 @@ std::vector Redis::xread(unsigned int count, unsigned int block, else { return rv->type() == RedisObject::Type::Array - ? (std::vector)*((RedisArray *)rv.get()) - : std::vector(); + ? (std::vector)*((RedisArray *)rv.get()) + : std::vector(); } } std::vector Redis::xreadgroup(const char *group, const char *consumer, - unsigned int count, unsigned int block_ms, bool noack, const char *key, - const char *id) + unsigned int count, unsigned int block_ms, bool noack, const char *key, + const char *id) { ArgList argList = ArgList{"GROUP", group, consumer}; - if(count > 0) + if (count > 0) { argList.push_back("COUNT"); argList.push_back(String(count)); } - if(block_ms > 0) + if (block_ms > 0) { argList.push_back("BLOCK"); argList.push_back(String(block_ms)); } - if(noack == true) + if (noack == true) { argList.push_back("NOACK"); } - if(key != NULL && strlen(key) > 0) + if (key != NULL && strlen(key) > 0) { argList.push_back("STREAMS"); argList.push_back(key); @@ -529,7 +529,7 @@ std::vector Redis::xreadgroup(const char *group, const char *consumer, auto rv = RedisCommand("XREADGROUP", argList).issue(conn); - if(rv->type() == RedisObject::Type::InternalError) + if (rv->type() == RedisObject::Type::InternalError) { std::vector r = std::vector(); String error_message = (String)(((RedisInternalError *)rv.get())->RESP()); @@ -539,17 +539,17 @@ std::vector Redis::xreadgroup(const char *group, const char *consumer, else { return rv->type() == RedisObject::Type::Array - ? (std::vector)*((RedisArray *)rv.get()) - : std::vector(); + ? (std::vector)*((RedisArray *)rv.get()) + : std::vector(); } } std::vector Redis::xrevrange(const char *key, const char *end, - const char *start, unsigned int count) + const char *start, unsigned int count) { ArgList argList = ArgList{key, end, start}; - if(count > 0) + if (count > 0) { argList.push_back("COUNT"); argList.push_back(String(count)); @@ -557,7 +557,7 @@ std::vector Redis::xrevrange(const char *key, const char *end, auto rv = RedisCommand("XREVRANGE", argList).issue(conn); - if(rv->type() == RedisObject::Type::InternalError) + if (rv->type() == RedisObject::Type::InternalError) { std::vector r = std::vector(); String error_message = (String)(((RedisInternalError *)rv.get())->RESP()); @@ -567,17 +567,17 @@ std::vector Redis::xrevrange(const char *key, const char *end, else { return rv->type() == RedisObject::Type::Array - ? (std::vector)*((RedisArray *)rv.get()) - : std::vector(); + ? (std::vector)*((RedisArray *)rv.get()) + : std::vector(); } } int Redis::xtrim(const char *key, const char *strategy, XtrimCompareType compare, const int threshold, const int count) { - if(compare == XtrimCompareAtLeast) + if (compare == XtrimCompareAtLeast) { - if(count > 0) + if (count > 0) { TRCMD(int, "XTRIM", key, strategy, String(char(compare)), String(threshold), "LIMIT", String(count)); @@ -589,7 +589,7 @@ int Redis::xtrim(const char *key, const char *strategy, XtrimCompareType compare } else { - TRCMD(int, "XTRIM", key, strategy, String(char(compare)), + TRCMD(int, "XTRIM", key, strategy, String(char(compare)), String(threshold)); } } @@ -670,7 +670,8 @@ RedisSubscribeResult Redis::startSubscribingNonBlocking(RedisMsgCallback message { loopCallback(); auto msg = RedisObject::parseTypeNonBlocking(conn); - if (msg == nullptr) { + if (msg == nullptr) + { continue; } @@ -716,9 +717,11 @@ RedisSubscribeResult Redis::startSubscribingNonBlocking(RedisMsgCallback message RedisSubscribeResult Redis::startSubscribing(RedisMsgCallback messageCallback, RedisMsgErrorCallback errCallback) { - return startSubscribingNonBlocking(messageCallback, []{}, errCallback); + return startSubscribingNonBlocking( + messageCallback, [] {}, errCallback); } -bool Redis::isErrorReturn(std::vector& returnVec) { +bool Redis::isErrorReturn(std::vector &returnVec) +{ return ((returnVec[0].c_str())[0] == '-'); } diff --git a/Redis.h b/Redis.h index 041836d..26b14e3 100644 --- a/Redis.h +++ b/Redis.h @@ -414,8 +414,8 @@ class Redis * @param justid */ std::vector xautoclaim(const char *key, const char *group, - const char* consumer, unsigned int min_idle_time, const char *start, - unsigned int count, bool justid); + const char *consumer, unsigned int min_idle_time, const char *start, + unsigned int count, bool justid); /** * Change the ownership of a pending message @@ -426,11 +426,11 @@ class Redis * @param count * @param justid */ - std::vector xclaim(const char *key, const char* group, - const char *consumer, - unsigned int min_idle_time, const char *id, unsigned int idle_ms, - unsigned int time_ms, unsigned int retrycount, bool force, bool justid, - const char *lastid); + std::vector xclaim(const char *key, const char *group, + const char *consumer, + unsigned int min_idle_time, const char *id, unsigned int idle_ms, + unsigned int time_ms, unsigned int retrycount, bool force, bool justid, + const char *lastid); /** * Removes the specified entries from a stream, and returns the number of @@ -472,9 +472,9 @@ class Redis * @returns The number of pending messages that consumer had before deletion */ int xgroup_delconsumer(const char *key, const char *group, - const char *consumer); + const char *consumer); - /** + /** * Completely destroys a consumer group * @param key * @param group @@ -489,7 +489,7 @@ class Redis * @param id * @returns OK on success */ - bool xgroup_setid(const char* key, const char *group, const char *id); + bool xgroup_setid(const char *key, const char *group, const char *id); /** * Returns the list of consumers that belong to the `group` consumer @@ -498,7 +498,7 @@ class Redis * @param group * @returns A formatted vector */ - std::vector xinfo_consumers(const char *key, const char* group); + std::vector xinfo_consumers(const char *key, const char *group); /** * Returns the list of all consumer groups of the stream stored at `key` @@ -517,7 +517,7 @@ class Redis * @returns A formatted vector */ std::vector xinfo_stream(const char *key, bool full, - unsigned int count); + unsigned int count); /** * Returns the number of entries inside a stream at the specified key. @@ -536,9 +536,9 @@ class Redis * @param count * @param consumer */ - std::vector xpending(const char *key, const char* group, - unsigned int min_idle_time, const char *start, const char *end, - unsigned int count, const char *consumer); + std::vector xpending(const char *key, const char *group, + unsigned int min_idle_time, const char *start, const char *end, + unsigned int count, const char *consumer); /** * Returns the stream entries matching a given range of IDs @@ -549,7 +549,7 @@ class Redis * @returns A formatted vector */ std::vector xrange(const char *key, const char *start, - const char *end, unsigned int count); + const char *end, unsigned int count); /** * Read data from one stream, only returning entries with an ID greater than @@ -558,7 +558,7 @@ class Redis * @param id */ std::vector xread(unsigned int count, unsigned int block, - const char *key, const char *id); + const char *key, const char *id); /** * XREAD version supporting groups @@ -571,8 +571,8 @@ class Redis * @param id */ std::vector xreadgroup(const char *group, const char *consumer, - unsigned int count, unsigned int block_ms, bool noack, const char *key, - const char *id); + unsigned int count, unsigned int block_ms, bool noack, const char *key, + const char *id); /** * Returns a range with entries in reverse order @@ -582,7 +582,7 @@ class Redis * @param count */ std::vector xrevrange(const char *key, const char *end, - const char* start, unsigned int count); + const char *start, unsigned int count); /** * Trims the stream by evicting older entries if needed @@ -593,7 +593,7 @@ class Redis * @param count */ int xtrim(const char *key, const char *strategy, XtrimCompareType compare, - int threshold, int count); + int threshold, int count); // auxiliary functions @@ -601,14 +601,14 @@ class Redis * Check returnVec's first element for a first byte of "-": * @param returnVec * @returns true if returnVec is an error, false otherwise - */ - bool isErrorReturn(std::vector& returnVec); + */ + bool isErrorReturn(std::vector &returnVec); /** * Check returnString for the nil return value (currently "(nil)" to match Redis' underlying value) * @param returnString * @returns true if returnString is the nil return value, false otherwise - */ + */ static bool isNilReturn(String returnString) { return returnString == "(nil)"; } /** diff --git a/RedisInternal.cpp b/RedisInternal.cpp index 238df39..7da718b 100644 --- a/RedisInternal.cpp +++ b/RedisInternal.cpp @@ -81,7 +81,7 @@ RedisArray::operator std::vector() const { if (ro->type() == RedisObject::Type::Array) { - for (auto append_inner : ((RedisArray*)ro.get())->operator std::vector()) + for (auto append_inner : ((RedisArray *)ro.get())->operator std::vector()) { rv.push_back(append_inner); } @@ -161,7 +161,8 @@ static TypeParseMap g_TypeParseMap{ std::shared_ptr RedisObject::parseTypeNonBlocking(Client &client) { - if (client.connected() && !client.available()) { + if (client.connected() && !client.available()) + { return nullptr; } @@ -172,7 +173,8 @@ std::shared_ptr RedisObject::parseTypeNonBlocking(Client &client) } typeChar = (RedisObject::Type)client.read(); - if (typeChar == -1 || typeChar == '\r' || typeChar == '\n') { + if (typeChar == -1 || typeChar == '\r' || typeChar == '\n') + { return nullptr; }; @@ -194,7 +196,8 @@ std::shared_ptr RedisObject::parseTypeNonBlocking(Client &client) std::shared_ptr RedisObject::parseType(Client &client) { std::shared_ptr type = nullptr; - while (type==nullptr) { + while (type == nullptr) + { type = parseTypeNonBlocking(client); } return type; diff --git a/RedisInternal.h b/RedisInternal.h index ce29d67..18e36ff 100644 --- a/RedisInternal.h +++ b/RedisInternal.h @@ -55,7 +55,12 @@ class RedisObject /** Produce a human-readable String representation. * Base implementation only returns the type character, so should be overriden. */ - virtual operator String() { if(data) return data; return String("(nil)");} + virtual operator String() + { + if (data) + return data; + return String("(nil)"); + } Type type() const { return _type; }