You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced-usage.md
+92Lines changed: 92 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,6 +211,98 @@ To use Microsoft EntraID with AMR or ACR, for sure you will need to set up and c
211
211
212
212
[Use Microsoft Entra](https://learn.microsoft.com/en-us/azure/app-service/configure-authentication-provider-aad?tabs=workforce-configuration)
213
213
214
+
## HostAndPortMapper
215
+
216
+
When running Jedis in certain network environments, such as behind a NAT gateway, or within container orchestration systems like Docker or Kubernetes, the host and port that the client needs to connect to might be different from the host and port that the Redis Cluster nodes report. To handle this discrepancy, Jedis provides the `HostAndPortMapper` interface.
217
+
218
+
This allows you to dynamically map the address reported by a Redis node to a different address that the client can actually reach. You can implement this either by creating a dedicated class or by using a concise lambda expression.
219
+
220
+
### Example use case: NAT or Docker with different advertised ports
221
+
Suppose you run a Redis cluster inside Docker on a remote host.
222
+
Inside the cluster config, nodes announce addresses like:
223
+
```
224
+
172.18.0.2:6379
225
+
172.18.0.3:6379
226
+
172.18.0.4:6379
227
+
```
228
+
But externally, you reach them through the host IP with mapped ports:
229
+
```
230
+
my-redis.example.com:7001
231
+
my-redis.example.com:7002
232
+
my-redis.example.com:7003
233
+
```
234
+
### Implementing with a Dedicated Class
235
+
236
+
You can provide your mapping logic by creating a class that implements the `HostAndPortMapper` interface. This approach is useful for more complex mapping logic or for reusability.
Now, when JedisCluster discovers a node at "172.18.0.2:6379", the mapper will translate it to "localhost:7001" before attempting to connect.
282
+
283
+
### Implementing with a Lambda Expression
284
+
Since HostAndPortMapper is a functional interface (it has only one abstract method), you can also provide the implementation more concisely using a lambda expression. This is often preferred for simpler, inline mapping logic.
0 commit comments