Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added custom commands to redis proxy #38414

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ message RedisProxy {
// storm to busy redis server. This config is a protection to rate limit reconnection rate.
// If not set, there will be no rate limiting on the reconnection.
ConnectionRateLimit connection_rate_limit = 10;


repeated string custom_commands = 11;
}

message PrefixRoutes {
Expand Down
5 changes: 5 additions & 0 deletions source/extensions/filters/network/common/redis/client_impl.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "source/extensions/filters/network/common/redis/client_impl.h"

#include "envoy/extensions/filters/network/redis_proxy/v3/redis_proxy.pb.h"
#include "source/extensions/filters/network/common/redis/supported_commands.h"

namespace Envoy {
namespace Extensions {
Expand Down Expand Up @@ -57,6 +58,10 @@ ConfigImpl::ConfigImpl(
connection_rate_limit_enabled_ = false;
connection_rate_limit_per_sec_ = 100;
}

for (int i=0; i < config.custom_commands_size(); i++) {
Extensions::NetworkFilters::Common::Redis::SupportedCommands::addCustomCommand(config.custom_commands(i));
}
}

ClientPtr ClientImpl::create(Upstream::HostConstSharedPtr host, Event::Dispatcher& dispatcher,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace NetworkFilters {
namespace Common {
namespace Redis {

absl::flat_hash_set<std::string> SupportedCommands::simpleCmdHashSet;

RedisCommandStats::RedisCommandStats(Stats::SymbolTable& symbol_table, const std::string& prefix)
: symbol_table_(symbol_table), stat_name_set_(symbol_table_.makeSet("Redis")),
prefix_(stat_name_set_->add(prefix)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ namespace Common {
namespace Redis {

struct SupportedCommands {
/**
* @return commands which hash to a single server
*/
static const absl::flat_hash_set<std::string>& simpleCommands() {
CONSTRUCT_ON_FIRST_USE(
absl::flat_hash_set<std::string>, "append", "bf.add", "bf.card", "bf.exists", "bf.info",

SupportedCommands()
{
simpleCmdHashSet = { //A list of redis commands
"append", "bf.add", "bf.card", "bf.exists", "bf.info",
"bf.insert", "bf.loadchunk", "bf.madd", "bf.mexists", "bf.reserve", "bf.scandump",
"bitcount", "bitfield", "bitpos", "decr", "decrby", "dump", "expire", "expireat", "geoadd",
"geodist", "geohash", "geopos", "georadius_ro", "georadiusbymember_ro", "get", "getbit",
Expand All @@ -34,7 +33,15 @@ struct SupportedCommands {
"xautoclaim", "xclaim", "xdel", "xlen", "xpending", "xrange", "xrevrange", "xtrim", "zadd",
"zcard", "zcount", "zincrby", "zlexcount", "zpopmin", "zpopmax", "zrange", "zrangebylex",
"zrangebyscore", "zrank", "zrem", "zremrangebylex", "zremrangebyrank", "zremrangebyscore",
"zrevrange", "zrevrangebylex", "zrevrangebyscore", "zrevrank", "zscan", "zscore");
"zrevrange", "zrevrangebylex", "zrevrangebyscore", "zrevrank", "zscan", "zscore"
};
}

/**
* @return commands which hash to a single server
*/
static const absl::flat_hash_set<std::string>& simpleCommands() {
return simpleCmdHashSet;
}

/**
Expand Down Expand Up @@ -112,6 +119,14 @@ struct SupportedCommands {
*/
static const std::string& select() { CONSTRUCT_ON_FIRST_USE(std::string, "select"); }

/**
* adds custom commands to list of redis commands
*/
static void addCustomCommand(const std::string& cmd)
{
simpleCmdHashSet.insert(cmd);
}

/**
* @return commands which alters the state of redis
*/
Expand All @@ -138,6 +153,9 @@ struct SupportedCommands {
mget() == command || mset() == command || keys() == command || ping() == command ||
time() == command || quit() == command || select() == command);
}

private:
static absl::flat_hash_set<std::string> simpleCmdHashSet;
};

} // namespace Redis
Expand Down