Reputation: 21
Lettuce supported zadd's NX|XX|CH|INCR options on 2015 link.
But I can't find any thing support this in Lettuce's wrapper Spring data Redis (version:2.1.5).
It seem that the only two zadd methods that DefaultZSetOperations provide can't let me use NX|XX|CH|INCR options:
Boolean add(K key, V value, double score);
Long add(K key, Set<TypedTuple<V>> tuples);
So how can I use NX|XX|CH|INCR options on Spring data redis with Lettue?
Sorry for my poor english ,Thanks.
Upvotes: 2
Views: 743
Reputation: 1
I use script
String script = "return redis.call('zadd',KEYS[1],'NX',ARGV[1],ARGV[2])";
DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>(script,Long.class);
redisTemplate.execute(redisScript, Collections.singletonList(key),String.valueOf(score),value);
Upvotes: 0
Reputation: 2107
Not completely sure if this will 100% work the same for Lettuce. For Jedis, found that we have to use redisTemplate.execute(RedisCallback)
. A small example of using the ch
argument for indicating if any records where changed (opposed to just being added to the sorted set)
redisTemplate.execute(
(RedisCallback<Long>) connection -> connection.zSetCommands().zAdd(
leaderboardKey.getBytes(StandardCharsets.UTF_8),
membersToTuples(members),
RedisZSetCommands.ZAddArgs.empty().ch()
)
)
Upvotes: 1