[
https://issues.apache.org/jira/browse/NIFI-4504?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16304166#comment-16304166
]
ASF GitHub Bot commented on NIFI-4504:
--------------------------------------
Github user ijokarumawak commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2284#discussion_r158755719
--- Diff:
nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/main/java/org/apache/nifi/redis/service/RedisDistributedMapCacheClientService.java
---
@@ -187,6 +191,16 @@ public void close() throws IOException {
});
}
+ @Override
+ public <K, V> V removeAndGet(K key, Serializer<K> keySerializer,
Deserializer<V> valueDeserializer) throws IOException {
+ return withConnection(redisConnection -> {
+ final byte[] k = serialize(key, keySerializer);
+ final byte[] v = redisConnection.get(k);
+ redisConnection.del(k);
+ return valueDeserializer.deserialize(v);
--- End diff --
For multiple operations like these `get` and `del`, Redis provides
[multi](https://redis.io/commands/multi) to make those as an atomic execution.
Since other methods are implemented similarly, I don't have strong opinion to
use multi here, but we can submit another JIRA for future improvement. How do
you think?
http://www.rediscookbook.org/get_and_delete.html
https://stackoverflow.com/questions/11148383/how-to-implement-redis-multi-exec-by-using-spring-data-redis
> SimpleMapCache/PersistentMapCache: Add removeAndGet and removeByPatternAndGet
> -----------------------------------------------------------------------------
>
> Key: NIFI-4504
> URL: https://issues.apache.org/jira/browse/NIFI-4504
> Project: Apache NiFi
> Issue Type: Improvement
> Affects Versions: 1.4.0
> Reporter: Jon Kessler
> Assignee: Michael Moser
> Priority: Minor
>
> Typical map implementations return the value that was removed when performing
> a remove. Because you couldn't update the existing remove methods without it
> being a breaking change I suggest adding new versions of the remove and
> removeByPattern methods that return the removed value(s).
> These changes should also be applied up the chain to any class that makes use
> of these classes such as the MapCacheServer and
> AtomicDistributedMapCacheClient.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)