DATAREDIS-693 - Add support for UNLINK.

We now support UNLINK for both Jedis & Lettuce throughout the single node and cluster connection. Reactive support is only available for Lettuce.

Original pull request: #294.
This commit is contained in:
Christoph Strobl
2017-10-06 13:12:20 +02:00
committed by Mark Paluch
parent 3ec25eebb8
commit c11b8d89ea
13 changed files with 230 additions and 0 deletions

View File

@@ -252,6 +252,15 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
return convertAndReturn(delegate.del(keys), identityConverter);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#unlink(byte[][])
*/
@Override
public Long unlink(byte[]... keys) {
return convertAndReturn(delegate.unlink(keys), identityConverter);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisTxCommands#discard()
@@ -1785,6 +1794,15 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
return del(serializeMulti(keys));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#unlink(java.lang.String[])
*/
@Override
public Long unlink(String... keys) {
return unlink(serializeMulti(keys));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#echo(java.lang.String)

View File

@@ -68,6 +68,13 @@ public interface DefaultedRedisConnection extends RedisConnection {
return keyCommands().del(keys);
}
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
@Override
@Deprecated
default Long unlink(byte[]... keys) {
return keyCommands().unlink(keys);
}
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
@Override
@Deprecated

View File

@@ -264,6 +264,31 @@ public interface ReactiveKeyCommands {
*/
Flux<NumericResponse<KeyCommand, Long>> del(Publisher<KeyCommand> keys);
/**
* Unlink {@literal key}.
*
* @param keys must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/unlink">Redis Documentation: UNLINK</a>
* @since 2.1
*/
default Mono<Long> unlink(List<ByteBuffer> keys) {
Assert.notNull(keys, "Key must not be null!");
return unlink(Mono.just(keys)).next().map(NumericResponse::getOutput);
}
/**
* Unlink {@literal keys}.
*
* @param keys must not be {@literal null}.
* @return {@link Flux} of {@link NumericResponse} holding the {@literal key} removed along with the deletion result.
* @see <a href="http://redis.io/commands/unlink">Redis Documentation: UNLINK</a>
* @since 2.1
*/
Flux<NumericResponse<List<ByteBuffer>, Long>> unlink(Publisher<List<ByteBuffer>> keys);
/**
* Delete multiple {@literal keys} one in one batch.
*

View File

@@ -70,6 +70,18 @@ public interface RedisKeyCommands {
@Nullable
Long del(byte[]... keys);
/**
* Unlinks the {@code keys} from the keyspace. Unlike with {@link #del(byte[]...)} the actual removal here happens
* asynchronously.
*
* @param keys must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/unlink">Redis Documentation: UNLINK</a>
* @since 2.1
*/
@Nullable
Long unlink(byte[]... keys);
/**
* Determine the type stored at {@code key}.
*

View File

@@ -113,6 +113,18 @@ public interface StringRedisConnection extends RedisConnection {
*/
Long del(String... keys);
/**
* Unlinks the {@code keys} from the keyspace. Unlike with {@link #del(byte[]...)} the actual removal here happens
* asynchronously.
*
* @param keys must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="http://redis.io/commands/unlink">Redis Documentation: UNLINK</a>
* @since 2.1
*/
@Nullable
Long unlink(String... keys);
/**
* Determine the type stored at {@code key}.
*

View File

@@ -81,6 +81,20 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
.resultsAsList().size();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#unlink(byte[][])
*/
@Nullable
@Override
public Long unlink(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
return connection.<Long> execute("UNLINK", Arrays.asList(keys), Collections.emptyList()).stream()
.mapToLong(val -> val).sum();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#type(byte[])

View File

@@ -120,6 +120,19 @@ class JedisKeyCommands implements RedisKeyCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#unlink(byte[][])
*/
@Nullable
@Override
public Long unlink(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
return Long.class.cast(connection.execute("UNLINK", keys));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#type(byte[])

View File

@@ -126,6 +126,30 @@ class LettuceKeyCommands implements RedisKeyCommands {
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#unlink(byte[][])
*/
@Override
public Long unlink(byte[]... keys) {
Assert.notNull(keys, "Keys must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newLettuceResult(getAsyncConnection().unlink(keys)));
return null;
}
if (isQueueing()) {
transaction(connection.newLettuceResult(getAsyncConnection().unlink(keys)));
return null;
}
return getConnection().unlink(keys);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#type(byte[])

View File

@@ -175,6 +175,22 @@ class LettuceReactiveKeyCommands implements ReactiveKeyCommands {
}));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.ReactiveRedisConnection.ReactiveKeyCommands#unlink(org.reactivestreams.Publisher)
*/
@Override
public Flux<NumericResponse<List<ByteBuffer>, Long>> unlink(Publisher<List<ByteBuffer>> keysCollection) {
return connection.execute(cmd -> Flux.from(keysCollection).flatMap((keys) -> {
Assert.notEmpty(keys, "Keys must not be null!");
return cmd.unlink(keys.stream().collect(Collectors.toList()).toArray(new ByteBuffer[keys.size()]))
.map((value) -> new NumericResponse<>(keys, value));
}));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.ReactiveRedisConnection.ReactiveKeyCommands#mDel(org.reactivestreams.Publisher)