diff --git a/src/sw/redis++/errors.h b/src/sw/redis++/errors.h index 44d629e5..be9e42ab 100644 --- a/src/sw/redis++/errors.h +++ b/src/sw/redis++/errors.h @@ -152,6 +152,13 @@ void throw_error(redisContext &context, const std::string &err_info); void throw_error(const redisReply &reply); +template +inline void range_check(const char *cmd, Input first, Input last) { + if (first == last) { + throw Error(std::string(cmd) + ": no key specified"); + } +} + } } diff --git a/src/sw/redis++/queued_redis.h b/src/sw/redis++/queued_redis.h index ae1ad6f9..2320ebb6 100644 --- a/src/sw/redis++/queued_redis.h +++ b/src/sw/redis++/queued_redis.h @@ -26,6 +26,7 @@ #include "reply.h" #include "command.h" #include "redis.h" +#include "errors.h" namespace sw { @@ -139,6 +140,8 @@ class QueuedRedis { template QueuedRedis& del(Input first, Input last) { + range_check("DEL", first, last); + return command(cmd::del_range, first, last); } @@ -157,6 +160,8 @@ class QueuedRedis { template QueuedRedis& exists(Input first, Input last) { + range_check("EXISTS", first, last); + return command(cmd::exists_range, first, last); } @@ -273,6 +278,8 @@ class QueuedRedis { template QueuedRedis& touch(Input first, Input last) { + range_check("TOUCH", first, last); + return command(cmd::touch_range, first, last); } @@ -295,6 +302,8 @@ class QueuedRedis { template QueuedRedis& unlink(Input first, Input last) { + range_check("UNLINK", first, last); + return command(cmd::unlink_range, first, last); } @@ -334,6 +343,8 @@ class QueuedRedis { const StringView &destination, Input first, Input last) { + range_check("BITOP", first, last); + return command(cmd::bitop_range, op, destination, first, last); } @@ -389,6 +400,8 @@ class QueuedRedis { template QueuedRedis& mget(Input first, Input last) { + range_check("MGET", first, last); + return command(cmd::mget, first, last); } @@ -399,6 +412,8 @@ class QueuedRedis { template QueuedRedis& mset(Input first, Input last) { + range_check("MSET", first, last); + return command(cmd::mset, first, last); } @@ -409,6 +424,8 @@ class QueuedRedis { template QueuedRedis& msetnx(Input first, Input last) { + range_check("MSETNX", first, last); + return command(cmd::msetnx, first, last); } @@ -477,6 +494,8 @@ class QueuedRedis { template QueuedRedis& blpop(Input first, Input last, long long timeout) { + range_check("BLPOP", first, last); + return command(cmd::blpop_range, first, last, timeout); } @@ -509,6 +528,8 @@ class QueuedRedis { template QueuedRedis& brpop(Input first, Input last, long long timeout) { + range_check("BRPOP", first, last); + return command(cmd::brpop_range, first, last, timeout); } @@ -567,6 +588,8 @@ class QueuedRedis { template QueuedRedis& lpush(const StringView &key, Input first, Input last) { + range_check("LPUSH", first, last); + return command(cmd::lpush_range, key, first, last); } @@ -611,6 +634,8 @@ class QueuedRedis { template QueuedRedis& rpush(const StringView &key, Input first, Input last) { + range_check("RPUSH", first, last); + return command(cmd::rpush_range, key, first, last); } @@ -631,6 +656,8 @@ class QueuedRedis { template QueuedRedis& hdel(const StringView &key, Input first, Input last) { + range_check("HDEL", first, last); + return command(cmd::hdel_range, key, first, last); } @@ -673,6 +700,8 @@ class QueuedRedis { template QueuedRedis& hmget(const StringView &key, Input first, Input last) { + range_check("HMGET", first, last); + return command(cmd::hmget, key, first, last); } @@ -683,6 +712,8 @@ class QueuedRedis { template QueuedRedis& hmset(const StringView &key, Input first, Input last) { + range_check("HMSET", first, last); + return command(cmd::hmset, key, first, last); } @@ -727,6 +758,8 @@ class QueuedRedis { auto hset(const StringView &key, Input first, Input last) -> typename std::enable_if::value, QueuedRedis&>::type { + range_check("HSET", first, last); + return command(cmd::hset_range, key, first, last); } @@ -759,6 +792,8 @@ class QueuedRedis { template QueuedRedis& sadd(const StringView &key, Input first, Input last) { + range_check("SADD", first, last); + return command(cmd::sadd_range, key, first, last); } @@ -773,6 +808,8 @@ class QueuedRedis { template QueuedRedis& sdiff(Input first, Input last) { + range_check("SDIFF", first, last); + return command(cmd::sdiff, first, last); } @@ -789,6 +826,8 @@ class QueuedRedis { QueuedRedis& sdiffstore(const StringView &destination, Input first, Input last) { + range_check("SDIFFSTORE", first, last); + return command(cmd::sdiffstore_range, destination, first, last); } @@ -799,6 +838,8 @@ class QueuedRedis { template QueuedRedis& sinter(Input first, Input last) { + range_check("SINTER", first, last); + return command(cmd::sinter, first, last); } @@ -815,6 +856,8 @@ class QueuedRedis { QueuedRedis& sinterstore(const StringView &destination, Input first, Input last) { + range_check("SINTERSTORE", first, last); + return command(cmd::sinterstore_range, destination, first, last); } @@ -859,6 +902,8 @@ class QueuedRedis { template QueuedRedis& srem(const StringView &key, Input first, Input last) { + range_check("SREM", first, last); + return command(cmd::srem_range, key, first, last); } @@ -893,6 +938,8 @@ class QueuedRedis { template QueuedRedis& sunion(Input first, Input last) { + range_check("SUNION", first, last); + return command(cmd::sunion, first, last); } @@ -907,6 +954,8 @@ class QueuedRedis { template QueuedRedis& sunionstore(const StringView &destination, Input first, Input last) { + range_check("SUNIONSTORE", first, last); + return command(cmd::sunionstore_range, destination, first, last); } @@ -928,6 +977,8 @@ class QueuedRedis { template QueuedRedis& bzpopmax(Input first, Input last, long long timeout) { + range_check("BZPOPMAX", first, last); + return command(cmd::bzpopmax_range, first, last, timeout); } @@ -960,6 +1011,8 @@ class QueuedRedis { template QueuedRedis& bzpopmin(Input first, Input last, long long timeout) { + range_check("BZPOPMIN", first, last); + return command(cmd::bzpopmin_range, first, last, timeout); } @@ -996,6 +1049,8 @@ class QueuedRedis { Input last, UpdateType type = UpdateType::ALWAYS, bool changed = false) { + range_check("ZADD", first, last); + return command(cmd::zadd_range, key, first, last, type, changed); } @@ -1023,6 +1078,8 @@ class QueuedRedis { Input first, Input last, Aggregation type = Aggregation::SUM) { + range_check("ZINTERSTORE", first, last); + return command(cmd::zinterstore_range, destination, first, last, type); } @@ -1106,6 +1163,8 @@ class QueuedRedis { template QueuedRedis& zrem(const StringView &key, Input first, Input last) { + range_check("ZREM", first, last); + return command(cmd::zrem_range, key, first, last); } @@ -1208,6 +1267,8 @@ class QueuedRedis { Input first, Input last, Aggregation type = Aggregation::SUM) { + range_check("ZUNIONSTORE", first, last); + return command(cmd::zunionstore_range, destination, first, last, type); } @@ -1226,6 +1287,8 @@ class QueuedRedis { template QueuedRedis& pfadd(const StringView &key, Input first, Input last) { + range_check("PFADD", first, last); + return command(cmd::pfadd_range, key, first, last); } @@ -1240,6 +1303,8 @@ class QueuedRedis { template QueuedRedis& pfcount(Input first, Input last) { + range_check("PFCOUNT", first, last); + return command(cmd::pfcount_range, first, last); } @@ -1254,6 +1319,8 @@ class QueuedRedis { template QueuedRedis& pfmerge(const StringView &destination, Input first, Input last) { + range_check("PFMERGE", first, last); + return command(cmd::pfmerge_range, destination, first, last); } @@ -1273,6 +1340,8 @@ class QueuedRedis { QueuedRedis& geoadd(const StringView &key, Input first, Input last) { + range_check("GEOADD", first, last); + return command(cmd::geoadd_range, key, first, last); } @@ -1290,6 +1359,8 @@ class QueuedRedis { template QueuedRedis& geohash(const StringView &key, Input first, Input last) { + range_check("GEOHASH", first, last); + return command(cmd::geohash_range, key, first, last); } @@ -1300,6 +1371,8 @@ class QueuedRedis { template QueuedRedis& geopos(const StringView &key, Input first, Input last) { + range_check("GEOPOS", first, last); + return command(cmd::geopos_range, key, first, last); } @@ -1413,6 +1486,8 @@ class QueuedRedis { template QueuedRedis& script_exists(Input first, Input last) { + range_check("SCRIPT EXISTS", first, last); + return command(cmd::script_exists_range, first, last); } @@ -1447,6 +1522,8 @@ class QueuedRedis { template QueuedRedis& xack(const StringView &key, const StringView &group, Input first, Input last) { + range_check("XACK", first, last); + return command(cmd::xack_range, key, group, first, last); } @@ -1457,6 +1534,8 @@ class QueuedRedis { template QueuedRedis& xadd(const StringView &key, const StringView &id, Input first, Input last) { + range_check("XADD", first, last); + return command(cmd::xadd_range, key, id, first, last); } @@ -1472,6 +1551,8 @@ class QueuedRedis { Input last, long long count, bool approx = true) { + range_check("XADD", first, last); + return command(cmd::xadd_maxlen_range, key, id, first, last, count, approx); } @@ -1499,6 +1580,8 @@ class QueuedRedis { const std::chrono::milliseconds &min_idle_time, Input first, Input last) { + range_check("XCLAIM", first, last); + return command(cmd::xclaim_range, key, group, @@ -1523,6 +1606,8 @@ class QueuedRedis { template QueuedRedis& xdel(const StringView &key, Input first, Input last) { + range_check("XDEL", first, last); + return command(cmd::xdel_range, key, first, last); } @@ -1604,6 +1689,8 @@ class QueuedRedis { auto xread(Input first, Input last, long long count) -> typename std::enable_if::value, QueuedRedis&>::type { + range_check("XREAD", first, last); + return command(cmd::xread_range, first, last, count); } @@ -1634,6 +1721,8 @@ class QueuedRedis { long long count) -> typename std::enable_if::value, QueuedRedis&>::type { + range_check("XREAD", first, last); + return command(cmd::xread_block_range, first, last, timeout.count(), count); } @@ -1672,6 +1761,8 @@ class QueuedRedis { bool noack) -> typename std::enable_if::value, QueuedRedis&>::type { + range_check("XREADGROUP", first, last); + return command(cmd::xreadgroup_range, group, consumer, first, last, count, noack); } @@ -1740,6 +1831,8 @@ class QueuedRedis { bool noack) -> typename std::enable_if::value, QueuedRedis&>::type { + range_check("XREADGROUP", first, last); + return command(cmd::xreadgroup_block_range, group, consumer, diff --git a/src/sw/redis++/redis.hpp b/src/sw/redis++/redis.hpp index b1ae8a4f..63713fb5 100644 --- a/src/sw/redis++/redis.hpp +++ b/src/sw/redis++/redis.hpp @@ -64,9 +64,7 @@ auto Redis::command(const StringView &cmd_name, Args &&...args) template auto Redis::command(Input first, Input last) -> typename std::enable_if::value, ReplyUPtr>::type { - if (first == last) { - throw Error("command: empty range"); - } + range_check("command", first, last); auto cmd = [](Connection &connection, Input first, Input last) { CmdArgs cmd_args; @@ -125,9 +123,7 @@ auto Redis::command(Input first, Input last, Output output) template long long Redis::del(Input first, Input last) { - if (first == last) { - throw Error("DEL: no key specified"); - } + range_check("DEL", first, last); auto reply = command(cmd::del_range, first, last); @@ -136,9 +132,7 @@ long long Redis::del(Input first, Input last) { template long long Redis::exists(Input first, Input last) { - if (first == last) { - throw Error("EXISTS: no key specified"); - } + range_check("EXISTS", first, last); auto reply = command(cmd::exists_range, first, last); @@ -211,9 +205,7 @@ inline long long Redis::scan(long long cursor, template long long Redis::touch(Input first, Input last) { - if (first == last) { - throw Error("TOUCH: no key specified"); - } + range_check("TOUCH", first, last); auto reply = command(cmd::touch_range, first, last); @@ -222,9 +214,7 @@ long long Redis::touch(Input first, Input last) { template long long Redis::unlink(Input first, Input last) { - if (first == last) { - throw Error("UNLINK: no key specified"); - } + range_check("UNLINK", first, last); auto reply = command(cmd::unlink_range, first, last); @@ -239,9 +229,7 @@ inline long long Redis::wait(long long numslaves, const std::chrono::millisecond template long long Redis::bitop(BitOp op, const StringView &destination, Input first, Input last) { - if (first == last) { - throw Error("BITOP: no key specified"); - } + range_check("BITOP", first, last); auto reply = command(cmd::bitop_range, op, destination, first, last); @@ -250,9 +238,7 @@ long long Redis::bitop(BitOp op, const StringView &destination, Input first, Inp template void Redis::mget(Input first, Input last, Output output) { - if (first == last) { - throw Error("MGET: no key specified"); - } + range_check("MGET", first, last); auto reply = command(cmd::mget, first, last); @@ -261,9 +247,7 @@ void Redis::mget(Input first, Input last, Output output) { template void Redis::mset(Input first, Input last) { - if (first == last) { - throw Error("MSET: no key specified"); - } + range_check("MSET", first, last); auto reply = command(cmd::mset, first, last); @@ -272,9 +256,7 @@ void Redis::mset(Input first, Input last) { template bool Redis::msetnx(Input first, Input last) { - if (first == last) { - throw Error("MSETNX: no key specified"); - } + range_check("MSETNX", first, last); auto reply = command(cmd::msetnx, first, last); @@ -297,9 +279,7 @@ inline void Redis::setex(const StringView &key, template OptionalStringPair Redis::blpop(Input first, Input last, long long timeout) { - if (first == last) { - throw Error("BLPOP: no key specified"); - } + range_check("BLPOP", first, last); auto reply = command(cmd::blpop_range, first, last, timeout); @@ -315,9 +295,7 @@ OptionalStringPair Redis::blpop(Input first, template OptionalStringPair Redis::brpop(Input first, Input last, long long timeout) { - if (first == last) { - throw Error("BRPOP: no key specified"); - } + range_check("BRPOP", first, last); auto reply = command(cmd::brpop_range, first, last, timeout); @@ -339,9 +317,7 @@ inline OptionalString Redis::brpoplpush(const StringView &source, template inline long long Redis::lpush(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("LPUSH: no key specified"); - } + range_check("LPUSH", first, last); auto reply = command(cmd::lpush_range, key, first, last); @@ -357,9 +333,7 @@ inline void Redis::lrange(const StringView &key, long long start, long long stop template inline long long Redis::rpush(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("RPUSH: no key specified"); - } + range_check("RPUSH", first, last); auto reply = command(cmd::rpush_range, key, first, last); @@ -370,9 +344,7 @@ inline long long Redis::rpush(const StringView &key, Input first, Input last) { template inline long long Redis::hdel(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("HDEL: no key specified"); - } + range_check("HDEL", first, last); auto reply = command(cmd::hdel_range, key, first, last); @@ -395,9 +367,7 @@ inline void Redis::hkeys(const StringView &key, Output output) { template inline void Redis::hmget(const StringView &key, Input first, Input last, Output output) { - if (first == last) { - throw Error("HMGET: no key specified"); - } + range_check("HMGET", first, last); auto reply = command(cmd::hmget, key, first, last); @@ -406,9 +376,7 @@ inline void Redis::hmget(const StringView &key, Input first, Input last, Output template inline void Redis::hmset(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("HMSET: no key specified"); - } + range_check("HMSET", first, last); auto reply = command(cmd::hmset, key, first, last); @@ -453,9 +421,7 @@ template auto Redis::hset(const StringView &key, Input first, Input last) -> typename std::enable_if::value, long long>::type { - if (first == last) { - throw Error("HSET: no key specified"); - } + range_check("HSET", first, last); auto reply = command(cmd::hset_range, key, first, last); @@ -473,9 +439,7 @@ inline void Redis::hvals(const StringView &key, Output output) { template long long Redis::sadd(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("SADD: no key specified"); - } + range_check("SADD", first, last); auto reply = command(cmd::sadd_range, key, first, last); @@ -484,9 +448,7 @@ long long Redis::sadd(const StringView &key, Input first, Input last) { template void Redis::sdiff(Input first, Input last, Output output) { - if (first == last) { - throw Error("SDIFF: no key specified"); - } + range_check("SDIFF", first, last); auto reply = command(cmd::sdiff, first, last); @@ -497,9 +459,7 @@ template long long Redis::sdiffstore(const StringView &destination, Input first, Input last) { - if (first == last) { - throw Error("SDIFFSTORE: no key specified"); - } + range_check("SDIFFSTORE", first, last); auto reply = command(cmd::sdiffstore_range, destination, first, last); @@ -508,9 +468,7 @@ long long Redis::sdiffstore(const StringView &destination, template void Redis::sinter(Input first, Input last, Output output) { - if (first == last) { - throw Error("SINTER: no key specified"); - } + range_check("SINTER", first, last); auto reply = command(cmd::sinter, first, last); @@ -521,9 +479,7 @@ template long long Redis::sinterstore(const StringView &destination, Input first, Input last) { - if (first == last) { - throw Error("SINTERSTORE: no key specified"); - } + range_check("SINTERSTORE", first, last); auto reply = command(cmd::sinterstore_range, destination, first, last); @@ -553,9 +509,7 @@ void Redis::srandmember(const StringView &key, long long count, Output output) { template long long Redis::srem(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("SREM: no key specified"); - } + range_check("SREM", first, last); auto reply = command(cmd::srem_range, key, first, last); @@ -598,9 +552,7 @@ inline long long Redis::sscan(const StringView &key, template void Redis::sunion(Input first, Input last, Output output) { - if (first == last) { - throw Error("SUNION: no key specified"); - } + range_check("SUNION", first, last); auto reply = command(cmd::sunion, first, last); @@ -609,9 +561,7 @@ void Redis::sunion(Input first, Input last, Output output) { template long long Redis::sunionstore(const StringView &destination, Input first, Input last) { - if (first == last) { - throw Error("SUNIONSTORE: no key specified"); - } + range_check("SUNIONSTORE", first, last); auto reply = command(cmd::sunionstore_range, destination, first, last); @@ -668,9 +618,7 @@ long long Redis::zadd(const StringView &key, Input last, UpdateType type, bool changed) { - if (first == last) { - throw Error("ZADD: no key specified"); - } + range_check("ZADD", first, last); auto reply = command(cmd::zadd_range, key, first, last, type, changed); @@ -689,9 +637,7 @@ long long Redis::zinterstore(const StringView &destination, Input first, Input last, Aggregation type) { - if (first == last) { - throw Error("ZINTERSTORE: no key specified"); - } + range_check("ZINTERSTORE", first, last); auto reply = command(cmd::zinterstore_range, destination, @@ -767,9 +713,7 @@ void Redis::zrangebyscore(const StringView &key, template long long Redis::zrem(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("ZREM: no key specified"); - } + range_check("ZREM", first, last); auto reply = command(cmd::zrem_range, key, first, last); @@ -868,9 +812,7 @@ long long Redis::zunionstore(const StringView &destination, Input first, Input last, Aggregation type) { - if (first == last) { - throw Error("ZUNIONSTORE: no key specified"); - } + range_check("ZUNIONSTORE", first, last); auto reply = command(cmd::zunionstore_range, destination, @@ -885,9 +827,7 @@ long long Redis::zunionstore(const StringView &destination, template bool Redis::pfadd(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("PFADD: no key specified"); - } + range_check("PFADD", first, last); auto reply = command(cmd::pfadd_range, key, first, last); @@ -896,9 +836,7 @@ bool Redis::pfadd(const StringView &key, Input first, Input last) { template long long Redis::pfcount(Input first, Input last) { - if (first == last) { - throw Error("PFCOUNT: no key specified"); - } + range_check("PFCOUNT", first, last); auto reply = command(cmd::pfcount_range, first, last); @@ -909,9 +847,7 @@ template void Redis::pfmerge(const StringView &destination, Input first, Input last) { - if (first == last) { - throw Error("PFMERGE: no key specified"); - } + range_check("PFMERGE", first, last); auto reply = command(cmd::pfmerge_range, destination, first, last); @@ -924,9 +860,7 @@ template inline long long Redis::geoadd(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("GEOADD: no key specified"); - } + range_check("GEOADD", first, last); auto reply = command(cmd::geoadd_range, key, first, last); @@ -935,9 +869,7 @@ inline long long Redis::geoadd(const StringView &key, template void Redis::geohash(const StringView &key, Input first, Input last, Output output) { - if (first == last) { - throw Error("GEOHASH: no key specified"); - } + range_check("GEOHASH", first, last); auto reply = command(cmd::geohash_range, key, first, last); @@ -946,9 +878,7 @@ void Redis::geohash(const StringView &key, Input first, Input last, Output outpu template void Redis::geopos(const StringView &key, Input first, Input last, Output output) { - if (first == last) { - throw Error("GEOPOS: no key specified"); - } + range_check("GEOPOS", first, last); auto reply = command(cmd::geopos_range, key, first, last); @@ -1041,9 +971,7 @@ void Redis::evalsha(const StringView &script, template void Redis::script_exists(Input first, Input last, Output output) { - if (first == last) { - throw Error("SCRIPT EXISTS: no key specified"); - } + range_check("SCRIPT EXISTS", first, last); auto reply = command(cmd::script_exists_range, first, last); @@ -1194,9 +1122,7 @@ void Redis::xread(const StringView &key, template auto Redis::xread(Input first, Input last, long long count, Output output) -> typename std::enable_if::value>::type { - if (first == last) { - throw Error("XREAD: no key specified"); - } + range_check("XREAD", first, last); auto reply = command(cmd::xread_range, first, last, count); @@ -1225,9 +1151,7 @@ auto Redis::xread(Input first, long long count, Output output) -> typename std::enable_if::value>::type { - if (first == last) { - throw Error("XREAD: no key specified"); - } + range_check("XREAD", first, last); auto reply = command(cmd::xread_block_range, first, last, timeout.count(), count); @@ -1260,9 +1184,7 @@ auto Redis::xreadgroup(const StringView &group, bool noack, Output output) -> typename std::enable_if::value>::type { - if (first == last) { - throw Error("XREADGROUP: no key specified"); - } + range_check("XREADGROUP", first, last); auto reply = command(cmd::xreadgroup_range, group, consumer, first, last, count, noack); @@ -1304,9 +1226,7 @@ auto Redis::xreadgroup(const StringView &group, bool noack, Output output) -> typename std::enable_if::value>::type { - if (first == last) { - throw Error("XREADGROUP: no key specified"); - } + range_check("XREADGROUP", first, last); auto reply = command(cmd::xreadgroup_block_range, group, diff --git a/src/sw/redis++/redis_cluster.hpp b/src/sw/redis++/redis_cluster.hpp index 08218b36..5470ca6a 100644 --- a/src/sw/redis++/redis_cluster.hpp +++ b/src/sw/redis++/redis_cluster.hpp @@ -120,9 +120,7 @@ auto RedisCluster::command(Input first, Input last, Output output) template long long RedisCluster::del(Input first, Input last) { - if (first == last) { - throw Error("DEL: no key specified"); - } + range_check("DEL", first, last); auto reply = command(cmd::del_range, first, last); @@ -131,9 +129,7 @@ long long RedisCluster::del(Input first, Input last) { template long long RedisCluster::exists(Input first, Input last) { - if (first == last) { - throw Error("EXISTS: no key specified"); - } + range_check("EXISTS", first, last); auto reply = command(cmd::exists_range, first, last); @@ -169,9 +165,7 @@ inline void RedisCluster::restore(const StringView &key, template long long RedisCluster::touch(Input first, Input last) { - if (first == last) { - throw Error("TOUCH: no key specified"); - } + range_check("TOUCH", first, last); auto reply = command(cmd::touch_range, first, last); @@ -180,9 +174,7 @@ long long RedisCluster::touch(Input first, Input last) { template long long RedisCluster::unlink(Input first, Input last) { - if (first == last) { - throw Error("UNLINK: no key specified"); - } + range_check("UNLINK", first, last); auto reply = command(cmd::unlink_range, first, last); @@ -193,9 +185,7 @@ long long RedisCluster::unlink(Input first, Input last) { template long long RedisCluster::bitop(BitOp op, const StringView &destination, Input first, Input last) { - if (first == last) { - throw Error("BITOP: no key specified"); - } + range_check("BITOP", first, last); auto reply = _command(cmd::bitop_range, destination, op, destination, first, last); @@ -204,9 +194,7 @@ long long RedisCluster::bitop(BitOp op, const StringView &destination, Input fir template void RedisCluster::mget(Input first, Input last, Output output) { - if (first == last) { - throw Error("MGET: no key specified"); - } + range_check("MGET", first, last); auto reply = command(cmd::mget, first, last); @@ -215,9 +203,7 @@ void RedisCluster::mget(Input first, Input last, Output output) { template void RedisCluster::mset(Input first, Input last) { - if (first == last) { - throw Error("MSET: no key specified"); - } + range_check("MSET", first, last); auto reply = command(cmd::mset, first, last); @@ -226,9 +212,7 @@ void RedisCluster::mset(Input first, Input last) { template bool RedisCluster::msetnx(Input first, Input last) { - if (first == last) { - throw Error("MSETNX: no key specified"); - } + range_check("MSETNX", first, last); auto reply = command(cmd::msetnx, first, last); @@ -251,9 +235,7 @@ inline void RedisCluster::setex(const StringView &key, template OptionalStringPair RedisCluster::blpop(Input first, Input last, long long timeout) { - if (first == last) { - throw Error("BLPOP: no key specified"); - } + range_check("BLPOP", first, last); auto reply = command(cmd::blpop_range, first, last, timeout); @@ -269,9 +251,7 @@ OptionalStringPair RedisCluster::blpop(Input first, template OptionalStringPair RedisCluster::brpop(Input first, Input last, long long timeout) { - if (first == last) { - throw Error("BRPOP: no key specified"); - } + range_check("BRPOP", first, last); auto reply = command(cmd::brpop_range, first, last, timeout); @@ -293,9 +273,7 @@ inline OptionalString RedisCluster::brpoplpush(const StringView &source, template inline long long RedisCluster::lpush(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("LPUSH: no key specified"); - } + range_check("LPUSH", first, last); auto reply = command(cmd::lpush_range, key, first, last); @@ -311,9 +289,7 @@ inline void RedisCluster::lrange(const StringView &key, long long start, long lo template inline long long RedisCluster::rpush(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("RPUSH: no key specified"); - } + range_check("RPUSH", first, last); auto reply = command(cmd::rpush_range, key, first, last); @@ -324,9 +300,7 @@ inline long long RedisCluster::rpush(const StringView &key, Input first, Input l template inline long long RedisCluster::hdel(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("HDEL: no key specified"); - } + range_check("HDEL", first, last); auto reply = command(cmd::hdel_range, key, first, last); @@ -349,9 +323,7 @@ inline void RedisCluster::hkeys(const StringView &key, Output output) { template inline void RedisCluster::hmget(const StringView &key, Input first, Input last, Output output) { - if (first == last) { - throw Error("HMGET: no key specified"); - } + range_check("HMGET", first, last); auto reply = command(cmd::hmget, key, first, last); @@ -360,9 +332,7 @@ inline void RedisCluster::hmget(const StringView &key, Input first, Input last, template inline void RedisCluster::hmset(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("HMSET: no key specified"); - } + range_check("HMSET", first, last); auto reply = command(cmd::hmset, key, first, last); @@ -407,9 +377,7 @@ template auto RedisCluster::hset(const StringView &key, Input first, Input last) -> typename std::enable_if::value, long long>::type { - if (first == last) { - throw Error("HSET: no key specified"); - } + range_check("HSET", first, last); auto reply = command(cmd::hset_range, key, first, last); @@ -427,9 +395,7 @@ inline void RedisCluster::hvals(const StringView &key, Output output) { template long long RedisCluster::sadd(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("SADD: no key specified"); - } + range_check("SADD", first, last); auto reply = command(cmd::sadd_range, key, first, last); @@ -438,9 +404,7 @@ long long RedisCluster::sadd(const StringView &key, Input first, Input last) { template void RedisCluster::sdiff(Input first, Input last, Output output) { - if (first == last) { - throw Error("SDIFF: no key specified"); - } + range_check("SDIFF", first, last); auto reply = command(cmd::sdiff, first, last); @@ -451,9 +415,7 @@ template long long RedisCluster::sdiffstore(const StringView &destination, Input first, Input last) { - if (first == last) { - throw Error("SDIFFSTORE: no key specified"); - } + range_check("SDIFFSTORE", first, last); auto reply = command(cmd::sdiffstore_range, destination, first, last); @@ -462,9 +424,7 @@ long long RedisCluster::sdiffstore(const StringView &destination, template void RedisCluster::sinter(Input first, Input last, Output output) { - if (first == last) { - throw Error("SINTER: no key specified"); - } + range_check("SINTER", first, last); auto reply = command(cmd::sinter, first, last); @@ -475,9 +435,7 @@ template long long RedisCluster::sinterstore(const StringView &destination, Input first, Input last) { - if (first == last) { - throw Error("SINTERSTORE: no key specified"); - } + range_check("SINTERSTORE", first, last); auto reply = command(cmd::sinterstore_range, destination, first, last); @@ -507,9 +465,7 @@ void RedisCluster::srandmember(const StringView &key, long long count, Output ou template long long RedisCluster::srem(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("SREM: no key specified"); - } + range_check("SREM", first, last); auto reply = command(cmd::srem_range, key, first, last); @@ -552,9 +508,7 @@ inline long long RedisCluster::sscan(const StringView &key, template void RedisCluster::sunion(Input first, Input last, Output output) { - if (first == last) { - throw Error("SUNION: no key specified"); - } + range_check("SUNION", first, last); auto reply = command(cmd::sunion, first, last); @@ -563,9 +517,7 @@ void RedisCluster::sunion(Input first, Input last, Output output) { template long long RedisCluster::sunionstore(const StringView &destination, Input first, Input last) { - if (first == last) { - throw Error("SUNIONSTORE: no key specified"); - } + range_check("SUNIONSTORE", first, last); auto reply = command(cmd::sunionstore_range, destination, first, last); @@ -622,9 +574,7 @@ long long RedisCluster::zadd(const StringView &key, Input last, UpdateType type, bool changed) { - if (first == last) { - throw Error("ZADD: no key specified"); - } + range_check("ZADD", first, last); auto reply = command(cmd::zadd_range, key, first, last, type, changed); @@ -643,9 +593,7 @@ long long RedisCluster::zinterstore(const StringView &destination, Input first, Input last, Aggregation type) { - if (first == last) { - throw Error("ZINTERSTORE: no key specified"); - } + range_check("ZINTERSTORE", first, last); auto reply = command(cmd::zinterstore_range, destination, @@ -721,9 +669,7 @@ void RedisCluster::zrangebyscore(const StringView &key, template long long RedisCluster::zrem(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("ZREM: no key specified"); - } + range_check("ZREM", first, last); auto reply = command(cmd::zrem_range, key, first, last); @@ -822,9 +768,7 @@ long long RedisCluster::zunionstore(const StringView &destination, Input first, Input last, Aggregation type) { - if (first == last) { - throw Error("ZUNIONSTORE: no key specified"); - } + range_check("ZUNIONSTORE", first, last); auto reply = command(cmd::zunionstore_range, destination, @@ -839,9 +783,7 @@ long long RedisCluster::zunionstore(const StringView &destination, template bool RedisCluster::pfadd(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("PFADD: no key specified"); - } + range_check("PFADD", first, last); auto reply = command(cmd::pfadd_range, key, first, last); @@ -850,9 +792,7 @@ bool RedisCluster::pfadd(const StringView &key, Input first, Input last) { template long long RedisCluster::pfcount(Input first, Input last) { - if (first == last) { - throw Error("PFCOUNT: no key specified"); - } + range_check("PFCOUNT", first, last); auto reply = command(cmd::pfcount_range, first, last); @@ -863,9 +803,7 @@ template void RedisCluster::pfmerge(const StringView &destination, Input first, Input last) { - if (first == last) { - throw Error("PFMERGE: no key specified"); - } + range_check("PFMERGE", first, last); auto reply = command(cmd::pfmerge_range, destination, first, last); @@ -878,9 +816,7 @@ template inline long long RedisCluster::geoadd(const StringView &key, Input first, Input last) { - if (first == last) { - throw Error("GEOADD: no key specified"); - } + range_check("GEOADD", first, last); auto reply = command(cmd::geoadd_range, key, first, last); @@ -889,9 +825,7 @@ inline long long RedisCluster::geoadd(const StringView &key, template void RedisCluster::geohash(const StringView &key, Input first, Input last, Output output) { - if (first == last) { - throw Error("GEOHASH: no key specified"); - } + range_check("GEOHASH", first, last); auto reply = command(cmd::geohash_range, key, first, last); @@ -900,9 +834,7 @@ void RedisCluster::geohash(const StringView &key, Input first, Input last, Outpu template void RedisCluster::geopos(const StringView &key, Input first, Input last, Output output) { - if (first == last) { - throw Error("GEOPOS: no key specified"); - } + range_check("GEOPOS", first, last); auto reply = command(cmd::geopos_range, key, first, last); @@ -1150,9 +1082,7 @@ void RedisCluster::xread(const StringView &key, template auto RedisCluster::xread(Input first, Input last, long long count, Output output) -> typename std::enable_if::value>::type { - if (first == last) { - throw Error("XREAD: no key specified"); - } + range_check("XREAD", first, last); auto reply = command(cmd::xread_range, first, last, count); @@ -1181,9 +1111,7 @@ auto RedisCluster::xread(Input first, long long count, Output output) -> typename std::enable_if::value>::type { - if (first == last) { - throw Error("XREAD: no key specified"); - } + range_check("XREAD", first, last); auto reply = command(cmd::xread_block_range, first, last, timeout.count(), count); @@ -1216,9 +1144,7 @@ auto RedisCluster::xreadgroup(const StringView &group, bool noack, Output output) -> typename std::enable_if::value>::type { - if (first == last) { - throw Error("XREADGROUP: no key specified"); - } + range_check("XREADGROUP", first, last); auto reply = _command(cmd::xreadgroup_range, first->first, @@ -1268,9 +1194,7 @@ auto RedisCluster::xreadgroup(const StringView &group, bool noack, Output output) -> typename std::enable_if::value>::type { - if (first == last) { - throw Error("XREADGROUP: no key specified"); - } + range_check("XREADGROUP", first, last); auto reply = _command(cmd::xreadgroup_block_range, first->first,