-
Notifications
You must be signed in to change notification settings - Fork 996
dnsdist: add redis KVStore implementation #17441
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
Draft
esensar
wants to merge
5
commits into
PowerDNS:master
Choose a base branch
from
esensar:feature/rediskvstore
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d4b483c
dnsdist: add redis KVStore implementation
esensar 943084f
dnsdist: enable redis in full feature set in CI
esensar e88c01c
dnsdist: fix formatting in `redis.hh` and `redis-stats.hh`
esensar c45c119
dnsdist: add YAML configuration support for Redis
esensar ede59a6
dnsdist: remove pipeline functionality from `RedisClient`
esensar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * This file is part of PowerDNS or dnsdist. | ||
| * Copyright -- PowerDNS.COM B.V. and its contributors | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of version 2 of the GNU General Public License as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * In addition, for the avoidance of any doubt, permission is granted to | ||
| * link this program with OpenSSL and to (re)distribute the binaries | ||
| * produced as the result of such linking. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| */ | ||
| #include "dnsdist-lua.hh" | ||
| #include <memory> | ||
| #ifdef HAVE_REDIS | ||
| #include "redis.hh" | ||
| #endif /* HAVE_REDIS */ | ||
|
|
||
| void setupLuaBindingsRedis([[maybe_unused]] LuaContext& luaCtx, [[maybe_unused]] bool client) | ||
| { | ||
| #ifdef HAVE_REDIS | ||
| luaCtx.writeFunction("newRedisClient", [client](const std::string& url, std::optional<LuaAssociativeTable<boost::variant<bool, std::string>>> vars) { | ||
| if (client) { | ||
| return std::shared_ptr<RedisClient>(nullptr); | ||
| } | ||
|
|
||
| bool pipelineEnabled{true}; | ||
| int pipelineInterval{10}; | ||
| getOptionalValue<bool>(vars, "pipelineEnabled", pipelineEnabled); | ||
| getOptionalIntegerValue<int>("newRedisClient", vars, "pipelineInterval", pipelineInterval); | ||
| checkAllParametersConsumed("newRedisClient", vars); | ||
|
|
||
| return std::make_shared<RedisClient>(url, pipelineEnabled, pipelineInterval); | ||
| }); | ||
|
|
||
| luaCtx.registerFunction<std::string (std::shared_ptr<RedisClient>::*)(const std::string&)>("get", [](std::shared_ptr<RedisClient>& rc, const std::string& key) { | ||
| std::string result; | ||
| if (!rc) { | ||
| return result; | ||
| } | ||
|
|
||
| auto reply = RedisGetCommand{}(*rc, key); | ||
|
|
||
| if (reply->ok()) { | ||
| result = reply->getValue(); | ||
| } | ||
|
|
||
| return result; | ||
| }); | ||
|
|
||
| luaCtx.registerFunction<bool (std::shared_ptr<RedisClient>::*)(const std::string&)>("exists", [](std::shared_ptr<RedisClient>& rc, const std::string& key) { | ||
| if (!rc) { | ||
| return false; | ||
| } | ||
|
|
||
| auto reply = RedisExistsCommand{}(*rc, key); | ||
|
|
||
| if (reply->ok()) { | ||
| return reply->getValue(); | ||
| } | ||
|
|
||
| return false; | ||
| }); | ||
|
|
||
| luaCtx.registerFunction<std::string (std::shared_ptr<RedisClient>::*)(const std::string&, const std::string&)>("hget", [](std::shared_ptr<RedisClient>& rc, const std::string& hash_key, const std::string& key) { | ||
| std::string result; | ||
| if (!rc) { | ||
| return result; | ||
| } | ||
|
|
||
| auto reply = RedisHGetCommand{}(*rc, hash_key, key); | ||
|
|
||
| if (reply->ok()) { | ||
| result = reply->getValue(); | ||
| } | ||
|
|
||
| return result; | ||
| }); | ||
|
|
||
| luaCtx.registerFunction<bool (std::shared_ptr<RedisClient>::*)(const std::string&, const std::string&)>("hexists", [](std::shared_ptr<RedisClient>& rc, const std::string& hash_key, const std::string& key) { | ||
| if (!rc) { | ||
| return false; | ||
| } | ||
|
|
||
| auto reply = RedisHExistsCommand{}(*rc, hash_key, key); | ||
|
|
||
| if (reply->ok()) { | ||
| return reply->getValue(); | ||
| } | ||
|
|
||
| return false; | ||
| }); | ||
| #endif /* HAVE_REDIS */ | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| AC_DEFUN([DNSDIST_WITH_REDIS], [ | ||
| AC_MSG_CHECKING([whether we will we linking with libhiredis]) | ||
| HAVE_REDIS=0 | ||
| AC_ARG_WITH([redis], | ||
| AS_HELP_STRING([--with-redis], [use Redis @<:@default=auto@:>@]), | ||
| [with_redis=$withval], | ||
| [with_redis=auto] | ||
| ) | ||
| AC_MSG_RESULT([$with_redis]) | ||
|
|
||
| AS_IF([test "x$with_redis" != "xno"], [ | ||
| AS_IF([test "x$with_redis" = "xyes" -o "x$with_redis" = "xauto"], [ | ||
| PKG_CHECK_MODULES([REDIS], [libhiredis], [ | ||
| [HAVE_REDIS=1] | ||
| AC_DEFINE([HAVE_REDIS], [1], [Define to 1 if you have REDIS]) | ||
| ], | ||
| [AC_CHECK_HEADERS([hiredis/hiredis.h], | ||
| [AC_CHECK_LIB([hiredis], [redisConnect], | ||
| [ | ||
| REDIS_LIBS="-lhiredis" | ||
| AC_DEFINE([HAVE_REDIS], [1], [Define to 1 if you have REDIS]) | ||
| [HAVE_REDIS=1] | ||
| ], | ||
| [:] | ||
| )], | ||
| [:] | ||
| )] | ||
| ) | ||
| ]) | ||
| ]) | ||
| AC_SUBST(REDIS_LIBS) | ||
| AC_SUBST(REDIS_CFLAGS) | ||
| AM_CONDITIONAL([HAVE_REDIS], [test "x$REDIS_LIBS" != "x"]) | ||
| AS_IF([test "x$with_redis" = "xyes"], [ | ||
| AS_IF([test x"$REDIS_LIBS" = "x"], [ | ||
| AC_MSG_ERROR([Redis requested but libraries were not found]) | ||
| ]) | ||
| ]) | ||
| ]) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the idea is to share metrics between all RedisKVStore instances using the same parameters, right? What's the use case for defining several of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I wanted to prevent that case, to prevent confusion about the metrics. I thought the runtime error I threw below would prevent duplicate instances with the exact same params.
There is a use case for different parameters of course and that should be supported.