You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by ijokarumawak <gi...@git.apache.org> on 2017/12/27 03:02:04 UTC
[GitHub] nifi pull request #2284: NIFI-4504, NIFI-4505 added methods to MapCache API ...
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
---