Skip to content

Commit 064eb95

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

5 files changed

Lines changed: 69 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`), a LMDB database (:func:`newLMDBKVStore`), or a MMDB database (:func: `newMMDBKVStore`).
142+
The store can be a CDB (:func:`newCDBKVStore`), a LMDB database (:func:`newLMDBKVStore`), a MMDB database (:func: `newMMDBKVStore`), 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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,6 +2573,52 @@ MMDB
25732573

25742574
* ``mmap``: bool - If set to true, opens the database in memory-map mode.
25752575

2576+
Redis
2577+
~~~~~
2578+
2579+
.. class:: RedisClient
2580+
2581+
.. versionadded:: 2.2.0
2582+
2583+
.. method:: get(key)
2584+
2585+
Returns the (string) value of a key in Redis, if it exists (GET command).
2586+
2587+
:param str key: Key to look up.
2588+
:returns: The string value.
2589+
2590+
.. method:: exists(key)
2591+
2592+
Checks if the given key exists in Redis (EXISTS command).
2593+
2594+
:param str key: Key to look up.
2595+
:returns: true if the key exists, false otherwise.
2596+
2597+
.. method:: hget(hash_key, key)
2598+
2599+
Returns the value of a field in the hash stored at hash_key in Redis, if it exists (HGET command).
2600+
2601+
:param str hash_key: Key the hash is stored at.
2602+
:param str key: Field in hash to look up.
2603+
:returns: The string value.
2604+
2605+
.. method:: hexists(hash_key, key)
2606+
2607+
Checks if the given field exists in hash stored at hash_key in Redis (HEXISTS command).
2608+
2609+
:param str hash_key: Key the hash is stored at.
2610+
:param str key: Field in hash to look up.
2611+
:returns: true if the field exists, false otherwise.
2612+
2613+
.. function:: newRedisClient(url)
2614+
2615+
.. versionadded:: 2.2.0
2616+
2617+
Creates a new Redis client, connecting to the instance at the provided url.
2618+
2619+
:param string url: URL to the Redis instance.
2620+
:returns: The :class:`RedisClient` object
2621+
25762622
timespec
25772623
~~~~~~~~
25782624

pdns/dnsdistdist/docs/reference/kvs.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The first step is to get a :class:`KeyValueStore` object via one of the followin
1212
* :func:`newCDBKVStore` for a CDB database ;
1313
* :func:`newLMDBKVStore` for a LMDB one.
1414
* :func:`newMMDBKVStore` for a MMDB one.
15+
* :func:`newRedisKVStore` for a Redis client.
1516

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

@@ -136,3 +137,22 @@ If the value found in the LMDB database for the key '\\8powerdns\\3com\\0' was '
136137

137138
:param MMDB mmdb: The reference to an existing MMDB database created with :func:`openMMDB`.
138139
:param str-or-list queryParams: Key or list of keys to fetch from the retrieved object from the MMDB database. Use empty list to retrieve the whole object.
140+
141+
.. function:: newRedisKVStore(redis[, options]) -> KeyValueStore
142+
143+
.. versionadded:: 2.2.0
144+
145+
Return a new KeyValueStore object associated to the provided Redis client. The client can be created using :func:`newRedisClient`.
146+
147+
:param RedisClient redis: The reference to an existing Redis client created with :func:`newRedisClient`.
148+
:param table options: A table with key: value pairs with options.
149+
150+
Options:
151+
152+
* ``lookupAction``: str - Command to use when looking up keys in Redis. Check below for supported lookup actions.
153+
* ``dataName``: str - Additional value with different behavior depending on the lookup action.
154+
155+
Lookup actions:
156+
157+
* ``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.
158+
* ``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`), a LMDB database (:func:`newLMDBKVStore`), or a MMDB database (:func: `newMMDBKVStore`).
84+
The store can be a CDB (:func:`newCDBKVStore`), a LMDB database (:func:`newLMDBKVStore`), a MMDB database (:func: `newMMDBKVStore`), 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)