本文整理了Java中io.lettuce.core.KeyValue
类的一些代码示例,展示了KeyValue
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyValue
类的具体详情如下:
包路径:io.lettuce.core.KeyValue
类名称:KeyValue
[英]A key-value container extension to Value. A KeyValue requires always a non-null key on construction.
[中]值的键值容器扩展。KeyValue在构造时始终需要非null键。
代码示例来源:origin: lettuce-io/lettuce-core
@Override
public int hashCode() {
int result = key.hashCode();
result = 31 * result + (hasValue() ? getValue().hashCode() : 0);
return result;
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Flux<MultiValueResponse<HGetCommand, ByteBuffer>> hMGet(Publisher<HGetCommand> commands) {
return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
Assert.notNull(command.getKey(), "Key must not be null!");
Assert.notNull(command.getFields(), "Fields must not be null!");
Mono<List<KeyValue<ByteBuffer, ByteBuffer>>> result;
if (command.getFields().size() == 1) {
ByteBuffer key = command.getFields().iterator().next();
result = cmd.hget(command.getKey(), key.duplicate()).map(value -> KeyValue.fromNullable(key, value))
.map(Collections::singletonList).onErrorReturn(Collections.emptyList());
} else {
result = cmd.hmget(command.getKey(), command.getFields().stream().toArray(ByteBuffer[]::new)).collectList();
}
return result.map(value -> new MultiValueResponse<>(command,
value.stream().map(keyValue -> keyValue.getValueOrElse(null)).collect(Collectors.toList())));
}));
}
代码示例来源:origin: lettuce-io/lettuce-core
/**
* Returns a {@link KeyValue} consisting of the results of applying the given function to the value of this element. Mapping
* is performed only if a {@link #hasValue() value is present}.
*
* @param <R> The element type of the new {@link KeyValue}
* @param mapper a stateless function to apply to each element
* @return the new {@link KeyValue}
*/
@SuppressWarnings("unchecked")
public <R> KeyValue<K, R> map(Function<? super V, ? extends R> mapper) {
LettuceAssert.notNull(mapper, "Mapper function must not be null");
if (hasValue()) {
return new KeyValue<>(getKey(), mapper.apply(getValue()));
}
return (KeyValue<K, R>) this;
}
}
代码示例来源:origin: lettuce-io/lettuce-core
/**
* Creates a {@link KeyValue} from a {@code key} and{@code value}. The resulting value contains the value if the
* {@code value} is not null.
*
* @param key the key, must not be {@literal null}.
* @param value the value. May be {@literal null}.
* @param <K>
* @param <T>
* @param <V>
* @return the {@link KeyValue}
*/
public static <K, T extends V, V> KeyValue<K, V> fromNullable(K key, T value) {
if (value == null) {
return empty(key);
}
return new KeyValue<K, V>(key, value);
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Flux<PopResponse> bPop(Publisher<BPopCommand> commands) {
return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> {
Assert.notNull(command.getKeys(), "Keys must not be null!");
Assert.notNull(command.getDirection(), "Direction must not be null!");
long timeout = command.getTimeout().get(ChronoUnit.SECONDS);
Mono<PopResult> mappedMono = (ObjectUtils.nullSafeEquals(Direction.RIGHT, command.getDirection())
? cmd.brpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new))
: cmd.blpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new)))
.map(kv -> Arrays.asList(kv.getKey(), kv.getValue())).map(PopResult::new);
return mappedMono.map(value -> new PopResponse(command, value));
}));
}
代码示例来源:origin: lettuce-io/lettuce-core
@Override
public void set(ByteBuffer bytes) {
if (keyIterator == null) {
keyIterator = keys.iterator();
}
subscriber.onNext(output, KeyValue.fromNullable(keyIterator.next(), bytes == null ? null : codec.decodeValue(bytes)));
}
代码示例来源:origin: lettuce-io/lettuce-core
V value = keyValue.getValueOrElseThrow(() -> new IllegalArgumentException(
"Cannot bind empty KeyValue to a Redis command."));
args.addKey(keyValue.getKey());
args.addValue(value);
return;
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Flux<MultiValueResponse<List<ByteBuffer>, ByteBuffer>> mGet(Publisher<List<ByteBuffer>> keyCollections) {
return connection.execute(cmd -> Flux.from(keyCollections).concatMap((keys) -> {
Assert.notNull(keys, "Keys must not be null!");
return cmd.mget(keys.toArray(new ByteBuffer[0])).map((value) -> value.getValueOrElse(EMPTY_BYTE_BUFFER))
.collectList().map((values) -> new MultiValueResponse<>(keys, values));
}));
}
代码示例来源:origin: lettuce-io/lettuce-core
/**
* Returns an empty {@code KeyValue} instance with the {@code key} set. No value is present for this instance.
*
* @param key the key, must not be {@literal null}.
* @param <K>
* @param <V>
* @return the {@link KeyValue}
*/
public static <K, V> KeyValue<K, V> empty(K key) {
return new KeyValue<K, V>(key, null);
}
代码示例来源:origin: org.springframework.data/spring-data-redis
@Override
public Flux<PopResponse> bPop(Publisher<BPopCommand> commands) {
return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> {
Assert.notNull(command.getKeys(), "Keys must not be null!");
Assert.notNull(command.getDirection(), "Direction must not be null!");
long timeout = command.getTimeout().get(ChronoUnit.SECONDS);
Mono<PopResult> mappedMono = (ObjectUtils.nullSafeEquals(Direction.RIGHT, command.getDirection())
? cmd.brpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new))
: cmd.blpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new)))
.map(kv -> Arrays.asList(kv.getKey(), kv.getValue())).map(PopResult::new);
return mappedMono.map(value -> new PopResponse(command, value));
}));
}
代码示例来源:origin: lettuce-io/lettuce-core
@Override
protected ScanCursor nextScanCursor(ScanCursor scanCursor) {
MapScanCursor<K, V> cursor = getNextScanCursor(scanCursor);
chunk = cursor.getMap().keySet().stream().map(k -> KeyValue.fromNullable(k, cursor.getMap().get(k))).iterator();
return cursor;
}
代码示例来源:origin: io.lettuce/lettuce-core
V value = keyValue.getValueOrElseThrow(() -> new IllegalArgumentException(
"Cannot bind empty KeyValue to a Redis command."));
args.addKey(keyValue.getKey());
args.addValue(value);
return;
代码示例来源:origin: lettuce-io/lettuce-core
/**
* Creates a {@link KeyValue} from a {@code key} and an {@link Optional}. The resulting value contains the value from the
* {@link Optional} if a value is present. Value is empty if the {@link Optional} is empty.
*
* @param key the key, must not be {@literal null}.
* @param optional the optional. May be empty but never {@literal null}.
* @param <K>
* @param <T>
* @param <V>
* @return the {@link KeyValue}
*/
public static <K, T extends V, V> KeyValue<K, V> from(K key, Optional<T> optional) {
LettuceAssert.notNull(optional, "Optional must not be null");
if (optional.isPresent()) {
return new KeyValue<K, V>(key, optional.get());
}
return empty(key);
}
代码示例来源:origin: org.springframework.data/spring-data-redis
@Override
public Flux<MultiValueResponse<List<ByteBuffer>, ByteBuffer>> mGet(Publisher<List<ByteBuffer>> keyCollections) {
return connection.execute(cmd -> Flux.from(keyCollections).concatMap((keys) -> {
Assert.notNull(keys, "Keys must not be null!");
return cmd.mget(keys.toArray(new ByteBuffer[0])).map((value) -> value.getValueOrElse(EMPTY_BYTE_BUFFER))
.collectList().map((values) -> new MultiValueResponse<>(keys, values));
}));
}
代码示例来源:origin: lettuce-io/lettuce-core
/**
* Creates a {@link KeyValue} from a {@code key} and {@code value}. The resulting value contains the value.
*
* @param key the key. Must not be {@literal null}.
* @param value the value. Must not be {@literal null}.
* @param <K>
* @param <T>
* @param <V>
* @return the {@link KeyValue}
*/
public static <K, T extends V, V> KeyValue<K, V> just(K key, T value) {
LettuceAssert.notNull(value, "Value must not be null");
return new KeyValue<K, V>(key, value);
}
代码示例来源:origin: lettuce-io/lettuce-core
@Override
public String toString() {
return hasValue() ? String.format("KeyValue[%s, %s]", key, getValue()) : String.format("KeyValue[%s].empty", key);
}
代码示例来源:origin: io.lettuce/lettuce-core
/**
* Returns a {@link KeyValue} consisting of the results of applying the given function to the value of this element. Mapping
* is performed only if a {@link #hasValue() value is present}.
*
* @param <R> The element type of the new {@link KeyValue}
* @param mapper a stateless function to apply to each element
* @return the new {@link KeyValue}
*/
@SuppressWarnings("unchecked")
public <R> KeyValue<K, R> map(Function<? super V, ? extends R> mapper) {
LettuceAssert.notNull(mapper, "Mapper function must not be null");
if (hasValue()) {
return new KeyValue<>(getKey(), mapper.apply(getValue()));
}
return (KeyValue<K, R>) this;
}
}
代码示例来源:origin: apache/servicemix-bundles
@Override
public Flux<PopResponse> bPop(Publisher<BPopCommand> commands) {
return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> {
Assert.notNull(command.getKeys(), "Keys must not be null!");
Assert.notNull(command.getDirection(), "Direction must not be null!");
long timeout = command.getTimeout().get(ChronoUnit.SECONDS);
Mono<PopResult> mappedMono = (ObjectUtils.nullSafeEquals(Direction.RIGHT, command.getDirection())
? cmd.brpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new))
: cmd.blpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new)))
.map(kv -> Arrays.asList(kv.getKey(), kv.getValue())).map(PopResult::new);
return mappedMono.map(value -> new PopResponse(command, value));
}));
}
代码示例来源:origin: org.springframework.data/spring-data-redis
@Override
public Flux<MultiValueResponse<HGetCommand, ByteBuffer>> hMGet(Publisher<HGetCommand> commands) {
return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
Assert.notNull(command.getKey(), "Key must not be null!");
Assert.notNull(command.getFields(), "Fields must not be null!");
Mono<List<KeyValue<ByteBuffer, ByteBuffer>>> result;
if (command.getFields().size() == 1) {
ByteBuffer key = command.getFields().iterator().next();
result = cmd.hget(command.getKey(), key.duplicate()).map(value -> KeyValue.fromNullable(key, value))
.map(Collections::singletonList).onErrorReturn(Collections.emptyList());
} else {
result = cmd.hmget(command.getKey(), command.getFields().stream().toArray(ByteBuffer[]::new)).collectList();
}
return result.map(value -> new MultiValueResponse<>(command,
value.stream().map(keyValue -> keyValue.getValueOrElse(null)).collect(Collectors.toList())));
}));
}
代码示例来源:origin: lettuce-io/lettuce-core
@Override
public void set(ByteBuffer bytes) {
if (bytes != null) {
if (key == null) {
key = codec.decodeKey(bytes);
} else {
V value = codec.decodeValue(bytes);
output = KeyValue.fromNullable(key, value);
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!