Skip to content

Commit bfb1e0d

Browse files
committed
dnsdist: add RedisKVStore docs
Signed-off-by: Ensar Sarajčić <dev@ensarsarajcic.com>
1 parent b12a4bb commit bfb1e0d

5 files changed

Lines changed: 65 additions & 2 deletions

File tree

.github/actions/spell-check/expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ Hendriks
561561
Henk
562562
Hensbergen
563563
Heuer
564+
hexists
564565
HHIT
565566
hidesoadetails
566567
hidettl

pdns/dnsdistdist/docs/reference/actions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ The following actions exist.
139139

140140
Does a lookup into the key value store referenced by 'kvs' using the key returned by 'lookupKey',
141141
and storing the result if any into the tag named 'destinationTag'.
142-
The store can be a CDB (:func:`newCDBKVStore`) or a LMDB database (:func:`newLMDBKVStore`).
142+
The store can be a CDB (:func:`newCDBKVStore`), a LMDB database (:func:`newLMDBKVStore`) or a Redis instance (:func:`newRedisKVStore`).
143143
The key can be based on the qname (:func:`KeyValueLookupKeyQName` and :func:`KeyValueLookupKeySuffix`),
144144
source IP (:func:`KeyValueLookupKeySourceIP`) or the value of an existing tag (:func:`KeyValueLookupKeyTag`).
145145
Subsequent rules are processed after this action.

pdns/dnsdistdist/docs/reference/config.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,6 +2539,48 @@ LuaRingEntry
25392539

25402540
.. _timespec:
25412541

2542+
Redis
2543+
~~~~~
2544+
2545+
.. class:: RedisClient
2546+
2547+
.. versionadded:: 2.2.0
2548+
2549+
.. method:: get(key)
2550+
2551+
Returns the (string) value of a key in Redis, if it exists (GET command).
2552+
2553+
:param str key: Key to look up.
2554+
2555+
.. method:: exists(key)
2556+
2557+
Checks if the given key exists in Redis (EXISTS command).
2558+
2559+
:param str key: Key to look up.
2560+
2561+
.. method:: hget(hash_key, key)
2562+
2563+
Returns the value of a field in the hash stored at hash_key in Redis, if it exists (HGET command).
2564+
2565+
:param str hash_key: Key the hash is stored at.
2566+
:param str key: Field in hash to look up.
2567+
2568+
.. method:: hexists(hash_key, key)
2569+
2570+
Checks if the given field exists in hash stored at hash_key in Redis (HEXISTS command).
2571+
2572+
:param str hash_key: Key the hash is stored at.
2573+
:param str key: Field in hash to look up.
2574+
2575+
.. function:: newRedisClient(url)
2576+
2577+
.. versionadded:: 2.2.0
2578+
2579+
Creates a new Redis client, connecting to the instance at the provided url.
2580+
2581+
:param string url: URL to the Redis instance.
2582+
:returns: The :class:`RedisClient` object
2583+
25422584
timespec
25432585
~~~~~~~~
25442586

pdns/dnsdistdist/docs/reference/kvs.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The first step is to get a :class:`KeyValueStore` object via one of the followin
1111

1212
* :func:`newCDBKVStore` for a CDB database ;
1313
* :func:`newLMDBKVStore` for a LMDB one.
14+
* :func:`newRedisKVStore` for a Redis client.
1415

1516
Then the key used for the lookup can be selected via one of the following functions:
1617

@@ -126,3 +127,22 @@ If the value found in the LMDB database for the key '\\8powerdns\\3com\\0' was '
126127
:param string filename: The path to an existing LMDB database created with ``MDB_NOSUBDIR``
127128
:param string dbName: The name of the database to use
128129
:param bool noLock: Whether to open the database with the ``MDB_NOLOCK`` flag. Default is false
130+
131+
.. function:: newRedisKVStore(redis[, options]) -> KeyValueStore
132+
133+
.. versionadded:: 2.2.0
134+
135+
Return a new KeyValueStore object associated to the provided Redis client. The client can be created using :func:`newRedisClient`.
136+
137+
:param RedisClient redis: The reference to an existing Redis client created with :func:`newRedisClient`.
138+
:param table options: A table with key: value pairs with options.
139+
140+
Options:
141+
142+
* ``lookupAction``: str - Command to use when looking up keys in Redis. Check below for supported lookup actions.
143+
* ``dataName``: str - Additional value with different behavior depending on the lookup action.
144+
145+
Lookup actions:
146+
147+
* ``get``: str - The default lookup action. Uses Redis GET command to look up keys. ``dataName`` can be used to define a prefix to be added to all keys before looking up.
148+
* ``hget``: str - Uses Redis HGET command to look up keys as fields of a hash. ``dataName`` is required for this action and defines the key hash is stored at.

pdns/dnsdistdist/docs/reference/selectors.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Selectors can be combined via :func:`AndRule`, :func:`OrRule` and :func:`NotRule
8181
.. function:: KeyValueStoreLookupRule(kvs, lookupKey)
8282

8383
Return true if the key returned by 'lookupKey' exists in the key value store referenced by 'kvs'.
84-
The store can be a CDB (:func:`newCDBKVStore`) or a LMDB database (:func:`newLMDBKVStore`).
84+
The store can be a CDB (:func:`newCDBKVStore`), a LMDB database (:func:`newLMDBKVStore`) or a Redis instance (:func:`newRedisKVStore`).
8585
The key can be based on the qname (:func:`KeyValueLookupKeyQName` and :func:`KeyValueLookupKeySuffix`),
8686
source IP (:func:`KeyValueLookupKeySourceIP`) or the value of an existing tag (:func:`KeyValueLookupKeyTag`).
8787

0 commit comments

Comments
 (0)