Skip to content

Commit 4bb20c6

Browse files
Introduce Redis key prefix configuration, extend timeout settings, and enhance consumer authorization logic.
1 parent 472afb1 commit 4bb20c6

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/main/java/uk/gov/dbt/ndtp/federator/utils/RedisUtil.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private static JedisPooled buildAuthenticatedRedisConnection(
152152
}
153153

154154
private static String qualifyOffset(String key) {
155-
// Do not apply prefixing here; callers of get/set will apply key prefixing once.
155+
key = getPrefixedKey(key);
156156
return "topic:" + key + ":offset";
157157
}
158158

@@ -175,6 +175,30 @@ public long getOffset(String clientName, String topic) {
175175
return getOffset(clientName + "-" + topic);
176176
}
177177

178+
private String setOffset(String key, long value) {
179+
key = qualifyOffset(key);
180+
LOGGER.debug("Persisting offset in redis {} = {}", key, value);
181+
setValue(key, value);
182+
return "OK";
183+
}
184+
185+
public String setOffset(String clientName, String topic, long value) {
186+
return setOffset(clientName + "-" + topic, value);
187+
}
188+
189+
/**
190+
* Stores a value in Redis at the given key without encryption.
191+
* No TTL.
192+
*
193+
* @param key the Redis key
194+
* @param value the object to store
195+
* @param <T> type of the value
196+
* @return true if Redis SET returned "OK"
197+
*/
198+
public <T> boolean setValue(String key, T value) {
199+
return setValue(getPrefixedKey(key), value, null);
200+
}
201+
178202
/**
179203
* Stores a value in Redis at the given key with a TTL.
180204
* No encryption.

0 commit comments

Comments
 (0)