Skip to content

Commit 51122da

Browse files
alberttwongclaude
andauthored
NIFI-16582 Address review feedback for Redis atomic cache documentation
Convert the RedisDistributedMapCacheClientService additional details to Markdown so they appear in the NiFi 2.x UI, add an upgrade note for the new EVAL permission requirement, document that the single-node Cluster test does not exercise MOVED or ASK redirects, and describe expected TTL behavior in the replacement test comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b0e73a9 commit 51122da

4 files changed

Lines changed: 75 additions & 53 deletions

File tree

‎nifi-extension-bundles/nifi-redis-bundle/nifi-redis-extensions/src/main/resources/docs/org.apache.nifi.redis.service.RedisDistributedMapCacheClientService/additionalDetails.html‎

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
-->
15+
16+
# RedisDistributedMapCacheClientService
17+
18+
## Redis Enterprise Software and Redis Cloud
19+
20+
Configure a `RedisConnectionPoolService` and select it as the **Redis Connection Pool** for this service.
21+
22+
| Connection pool property | Value |
23+
|---|---|
24+
| **Redis Mode** | `Standalone` for a database endpoint that routes commands through the Redis proxy, including sharded databases. Select `Cluster` only if the endpoint exposes the Redis Cluster API and its advertised nodes are reachable from NiFi. |
25+
| **Connection String** | The database endpoint as `hostname:port`. Use the database endpoint, not a management console or REST API endpoint. Do not include a `redis://` or `rediss://` scheme. |
26+
| **Database Index** | `0`. Redis Enterprise Software and Redis Cloud identify databases by endpoint. |
27+
| **Username** | The database ACL user, or `default` when using the default user. |
28+
| **Password** | The database user's password, supplied through a sensitive parameter. |
29+
| **SSL Context Service** | Configure this when the database endpoint requires TLS. Trust the database CA, and supply a client certificate and private key when mutual TLS is required. |
30+
31+
`Standalone` describes the client connection topology. It does not require an unsharded Redis server and does not
32+
disable the availability or sharding provided by the Redis database endpoint. In `Standalone` mode, NiFi connects to
33+
the database proxy, and the proxy routes each command to the shard that owns the key, across nodes when the database
34+
spans several. See [proxy policies](https://redis.io/docs/latest/operate/rs/databases/configure/proxy-policy/) and
35+
[Redis Cloud clustering](https://redis.io/docs/latest/operate/rc/databases/configuration/clustering/).
36+
37+
`Cluster` mode uses the [OSS Cluster API](https://redis.io/docs/latest/operate/rs/clusters/optimize/oss-cluster-api/):
38+
the client discovers the hash slot topology, connects to the node that owns each key, and follows redirects. It can
39+
reduce forwarding inside the database, but it is optional and is not required to use a sharded or multi-node database.
40+
41+
## Atomic Operations and Permissions
42+
43+
Conditional insert and replace operations act on one key at a time. The get-and-insert and compare-and-set operations
44+
use `EVAL` with a single explicitly declared key, keeping the read, conditional write, and TTL update together on the
45+
server. `WATCH`, `MULTI`, and `EXEC` are not required. Scripts and values are binary safe. Existing keys, values, and
46+
raw-value revisions retain their format.
47+
48+
The Redis user needs permission for `EVAL` and the commands executed by these scripts (`GET` and `SET`), as well as
49+
commands used by the cache operations the flow calls (including `EXISTS`, `DEL`, `MSET`, and `EXPIRE`). Configure key
50+
permissions for the serialized cache keys. A server configured to prohibit scripting cannot use this atomic cache
51+
service.
52+
53+
TTL is applied when an entry is inserted or successfully replaced. A failed comparison or an insert against an
54+
existing key leaves the value and its expiration unchanged. A TTL of `0 secs` creates entries without expiration.
55+
56+
## Upgrading from Earlier Versions
57+
58+
Earlier versions implemented `getAndPutIfAbsent` and `replace` with `WATCH`, `MULTI`, and `EXEC`. Those operations
59+
now run as Lua scripts. Before upgrading, grant the Redis user permission for `EVAL`, `GET`, and `SET` on the
60+
serialized cache keys. A user that is allowed `WATCH`, `MULTI`, and `EXEC` but not `EVAL` fails these operations with
61+
a `NOPERM` error, and the cache entry is left unchanged.
62+
63+
## Deployment Considerations
64+
65+
Single-key atomicity applies at the endpoint executing the operation. Redis Active-Active replication does not provide
66+
a globally serialized compare-and-set across regions. Flows that require global coordination, such as duplicate
67+
detection or Wait/Notify, should use one authoritative database rather than independent writable Active-Active
68+
regions.
69+
70+
Bulk `putAll` retains its existing `MSET` behavior; it does not promise a transaction across multiple hash slots.
71+
Follow the database's multi-key command restrictions and use a common hash tag when a deployment requires keys in one
72+
slot.

‎nifi-extension-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/service/ITRedisClusterDistributedMapCacheClientService.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
/**
2020
* Runs the atomic cache contract against the Redis Cluster API, with all hash slots assigned to one node.
2121
* This exercises cluster command routing without requiring fixed Docker host ports or a multi-node network.
22+
* Because one node owns every slot, the client never receives MOVED or ASK redirects, so this test does not cover
23+
* redirect handling or slot migration between nodes.
2224
*/
2325
public class ITRedisClusterDistributedMapCacheClientService extends ITRedisDistributedMapCacheClientService {
2426

‎nifi-extension-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/service/ITRedisDistributedMapCacheClientService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public void testZeroTtlCreatesPersistentEntries() throws IOException {
279279
for (String key : List.of("put", "get", "replace")) {
280280
assertEquals(-1L, connection.keyCommands().ttl(key.getBytes(StandardCharsets.UTF_8)));
281281
}
282-
// A replacement without TTL must remove an existing expiration, as SET did before this change.
282+
// A successful replacement with TTL disabled removes any existing expiration.
283283
connection.keyCommands().expire("replace".getBytes(StandardCharsets.UTF_8), 20);
284284
assertTrue(cacheClient.replace(new AtomicCacheEntry<>("replace", "v2", "v1".getBytes(StandardCharsets.UTF_8)),
285285
STRING_SERIALIZER, STRING_SERIALIZER));

0 commit comments

Comments
 (0)