Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,16 @@ public RedisFuture<List<V>> zinter(ZAggregateArgs aggregateArgs, K... keys) {
return dispatch(commandBuilder.zinter(aggregateArgs, keys));
}

@Override
public RedisFuture<Long> zintercard(K... keys) {
return dispatch(commandBuilder.zintercard(keys));
}

@Override
public RedisFuture<Long> zintercard(int limit, K... keys) {
return dispatch(commandBuilder.zintercard(limit, keys));
}

@Override
public RedisFuture<List<ScoredValue<V>>> zinterWithScores(K... keys) {
return dispatch(commandBuilder.zinterWithScores(keys));
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,16 @@ public Flux<V> zinter(ZAggregateArgs aggregateArgs, K... keys) {
return createDissolvingFlux(() -> commandBuilder.zinter(aggregateArgs, keys));
}

@Override
public Mono<Long> zintercard(K... keys) {
return createMono(() -> commandBuilder.zintercard(keys));
}

@Override
public Mono<Long> zintercard(int limit, K... keys) {
return createMono(() -> commandBuilder.zintercard(limit, keys));
}

@Override
public Flux<ScoredValue<V>> zinterWithScores(K... keys) {
return createDissolvingFlux(() -> commandBuilder.zinterWithScores(keys));
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3057,6 +3057,20 @@ Command<K, V, List<V>> zinter(ZAggregateArgs aggregateArgs, K... keys) {
return createCommand(ZINTER, new ValueListOutput<>(codec), args);
}

Command<K, V, Long> zintercard(K... keys) {
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec).add(keys.length).addKeys(keys);
return createCommand(ZINTERCARD, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> zintercard(int limit, K... keys) {
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec).add(keys.length).addKeys(keys).add(LIMIT).add(limit);
return createCommand(ZINTERCARD, new IntegerOutput<>(codec), args);
}

Command<K, V, List<ScoredValue<V>>> zinterWithScores(K... keys) {
notEmpty(keys);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,24 @@ public interface RedisSortedSetAsyncCommands<K, V> {
*/
RedisFuture<List<V>> zinter(ZAggregateArgs aggregateArgs, K... keys);

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
RedisFuture<Long> zintercard(K... keys);

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param limit If the intersection cardinality reaches limit partway through the computation, the algorithm will exit and
* yield limit as the cardinality
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
RedisFuture<Long> zintercard(int limit, K... keys);

/**
* Intersect multiple sorted sets and returns the resulting sorted.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,24 @@ public interface RedisSortedSetReactiveCommands<K, V> {
*/
Flux<V> zinter(ZAggregateArgs aggregateArgs, K... keys);

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
Mono<Long> zintercard(K... keys);

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param limit If the intersection cardinality reaches limit partway through the computation, the algorithm will exit and
* yield limit as the cardinality
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
Mono<Long> zintercard(int limit, K... keys);

/**
* Intersect multiple sorted sets and returns the resulting sorted.
*
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/lettuce/core/api/sync/RedisSortedSetCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,24 @@ public interface RedisSortedSetCommands<K, V> {
*/
List<V> zinter(ZAggregateArgs aggregateArgs, K... keys);

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
Long zintercard(K... keys);

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param limit If the intersection cardinality reaches limit partway through the computation, the algorithm will exit and
* yield limit as the cardinality
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
Long zintercard(int limit, K... keys);

/**
* Intersect multiple sorted sets and returns the resulting sorted.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -278,6 +278,24 @@ public interface NodeSelectionSortedSetAsyncCommands<K, V> {
*/
AsyncExecutions<List<V>> zinter(ZAggregateArgs aggregateArgs, K... keys);

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
AsyncExecutions<Long> zintercard(K... keys);

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param limit If the intersection cardinality reaches limit partway through the computation, the algorithm will exit and
* yield limit as the cardinality
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
AsyncExecutions<Long> zintercard(int limit, K... keys);

/**
* Intersect multiple sorted sets and returns the resulting sorted.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -278,6 +278,24 @@ public interface NodeSelectionSortedSetCommands<K, V> {
*/
Executions<List<V>> zinter(ZAggregateArgs aggregateArgs, K... keys);

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
Executions<Long> zintercard(K... keys);

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param limit If the intersection cardinality reaches limit partway through the computation, the algorithm will exit and
* yield limit as the cardinality
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
Executions<Long> zintercard(int limit, K... keys);

/**
* Intersect multiple sorted sets and returns the resulting sorted.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/protocol/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public enum CommandType implements ProtocolKeyword {

// Sorted Set

BZPOPMIN, BZPOPMAX, ZADD, ZCARD, ZCOUNT, ZDIFF, ZDIFFSTORE, ZINCRBY, ZINTER, ZINTERSTORE, ZLEXCOUNT, ZMSCORE, ZPOPMIN, ZPOPMAX, ZRANDMEMBER, ZRANGE, ZRANGEBYSCORE, ZRANGESTORE, ZRANK, ZREM, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZREVRANGE, ZREVRANGEBYLEX, ZREVRANGEBYSCORE, ZREVRANK, ZSCAN, ZSCORE, ZUNION, ZUNIONSTORE, ZREMRANGEBYLEX, ZRANGEBYLEX,
BZPOPMIN, BZPOPMAX, ZADD, ZCARD, ZCOUNT, ZDIFF, ZDIFFSTORE, ZINCRBY, ZINTER, ZINTERCARD, ZINTERSTORE, ZLEXCOUNT, ZMSCORE, ZPOPMIN, ZPOPMAX, ZRANDMEMBER, ZRANGE, ZRANGEBYSCORE, ZRANGESTORE, ZRANK, ZREM, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZREVRANGE, ZREVRANGEBYLEX, ZREVRANGEBYSCORE, ZREVRANK, ZSCAN, ZSCORE, ZUNION, ZUNIONSTORE, ZREMRANGEBYLEX, ZRANGEBYLEX,

// Scripting

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,24 @@ interface RedisSortedSetCoroutinesCommands<K : Any, V : Any> {
*/
fun zinter(aggregateArgs: ZAggregateArgs, vararg keys: K): Flow<V>

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
suspend fun zintercard(vararg keys: K): Long?

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param limit If the intersection cardinality reaches limit partway through the computation, the algorithm will exit and
* yield limit as the cardinality
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
suspend fun zintercard(limit: Int, vararg keys: K): Long?

/**
* Intersect multiple sorted sets and returns the resulting sorted.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ internal class RedisSortedSetCoroutinesCommandsImpl<K : Any, V : Any>(internal v

override fun zinter(aggregateArgs: ZAggregateArgs, vararg keys: K): Flow<V> = ops.zinter(aggregateArgs, *keys).asFlow()

override suspend fun zintercard(vararg keys: K): Long? = ops.zintercard(*keys).awaitFirstOrNull()

override suspend fun zintercard(limit: Int, vararg keys: K): Long? = ops.zintercard(limit, *keys).awaitFirstOrNull()

override fun zinterWithScores(vararg keys: K): Flow<ScoredValue<V>> = ops.zinterWithScores(*keys).asFlow()

override fun zinterWithScores(aggregateArgs: ZAggregateArgs, vararg keys: K): Flow<ScoredValue<V>> = ops.zinterWithScores(aggregateArgs, *keys).asFlow()
Expand Down
18 changes: 18 additions & 0 deletions src/main/templates/io/lettuce/core/api/RedisSortedSetCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,24 @@ public interface RedisSortedSetCommands<K, V> {
*/
List<V> zinter(ZAggregateArgs aggregateArgs, K... keys);

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
Long zintercard(K... keys);

/**
* This command is similar to ZINTER, but instead of returning the result set, it returns just the cardinality of the result.
*
* @param limit If the intersection cardinality reaches limit partway through the computation, the algorithm will exit and
* yield limit as the cardinality
* @param keys the keys.
* @return Long Integer reply the number of elements in the resulting intersection.
*/
Long zintercard(int limit, K... keys);

/**
* Intersect multiple sorted sets and returns the resulting sorted.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ void zincrby() {
assertThat(redis.zincrby(key, -1.2, "a")).isEqualTo(-0.1, offset(0.1));
}

@Test
@EnabledOnCommand("ZINTERCARD")
void zintercard() {
redis.zadd("zset1", 1.0, "a", 2.0, "b");
redis.zadd("zset2", 2.0, "a", 1.0, "b");
assertThat(redis.zintercard("zset1", "zset2")).isEqualTo(2);
assertThat(redis.zintercard(1, "zset1", "zset2")).isEqualTo(1);
}

@Test
@SuppressWarnings({ "unchecked" })
void zinterstore() {
Expand Down