From f94df9f5352f1060968e920f408764a22eb44115 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Wed, 3 Sep 2014 11:27:04 +0200 Subject: [PATCH] DATAREDIS-340 - Polish performance improvement of zAdd using jedis. It turned out that the version check throttled performance so we moved things around to avoid iterating multiple times and still perform the check in a non intrusive way. --- .../redis/connection/jedis/JedisConnection.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java index f93305cd5..f10437cb5 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java @@ -19,8 +19,8 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -3107,21 +3107,21 @@ public class JedisConnection extends AbstractRedisConnection { private Map zAddArgs(Set tuples) { - Map args = new HashMap(); + Map args = new LinkedHashMap(tuples.size(), 1); + Set scores = new HashSet(tuples.size(), 1); - if (!JedisVersionUtil.atLeastJedis24()) { - int size = (int) (tuples.size() / 0.75) + 1; - Set scores = new HashSet(size); - for (Tuple tuple : tuples) { + boolean isAtLeastJedis24 = JedisVersionUtil.atLeastJedis24(); + + for (Tuple tuple : tuples) { + + if (!isAtLeastJedis24) { if (scores.contains(tuple.getScore())) { throw new UnsupportedOperationException( "Bulk add of multiple elements with the same score is not supported. Add the elements individually."); } scores.add(tuple.getScore()); } - } - for (Tuple tuple : tuples) { args.put(tuple.getValue(), tuple.getScore()); }