use of io.lettuce.core.ClientOptions in project spring-parent by mingyang66.
the class RedisDbLettuceConnectionConfiguration method createClientOptions.
/**
* ClientOptions 用于控制客户端行为的客户端选项
*
* @return
*/
private ClientOptions createClientOptions() {
ClientOptions.Builder builder = this.initializeClientOptionsBuilder();
Duration connectTimeout = this.getProperties().getConnectTimeout();
if (connectTimeout != null) {
builder.socketOptions(SocketOptions.builder().connectTimeout(connectTimeout).build());
}
return builder.timeoutOptions(TimeoutOptions.enabled()).build();
}
use of io.lettuce.core.ClientOptions in project lettuce-core by lettuce-io.
the class ClientsideCachingIntegrationTests method clientCachingResp2.
@Test
void clientCachingResp2() {
ClientOptions resp2 = ClientOptions.builder().protocolVersion(ProtocolVersion.RESP2).build();
redisClient.setOptions(resp2);
StatefulRedisConnection<String, String> data = redisClient.connect();
RedisCommands<String, String> commands = data.sync();
StatefulRedisPubSubConnection<String, String> pubSub = redisClient.connectPubSub();
List<String> invalidations = new CopyOnWriteArrayList<>();
commands.clientTracking(TrackingArgs.Builder.enabled().redirect(pubSub.sync().clientId()));
pubSub.addListener(new RedisPubSubAdapter<String, String>() {
@Override
public void message(String channel, String message) {
if (channel.equals("__redis__:invalidate")) {
invalidations.add(message);
}
}
});
pubSub.sync().subscribe("__redis__:invalidate");
commands.get("key1");
commands.get("key2");
assertThat(invalidations).isEmpty();
Map<String, String> keys = new HashMap<>();
keys.put("key1", "value1");
keys.put("key2", "value2");
commands.mset(keys);
Wait.untilEquals(2, invalidations::size).waitOrTimeout();
assertThat(invalidations).contains("key1", "key2");
data.close();
pubSub.close();
}
use of io.lettuce.core.ClientOptions in project lettuce-core by lettuce-io.
the class ClientsideCachingIntegrationTests method clientCachingResp3.
@Test
void clientCachingResp3() {
ClientOptions resp2 = ClientOptions.builder().protocolVersion(ProtocolVersion.RESP3).build();
redisClient.setOptions(resp2);
StatefulRedisConnection<String, String> data = redisClient.connect();
RedisCommands<String, String> commands = data.sync();
List<String> invalidations = new CopyOnWriteArrayList<>();
commands.clientTracking(TrackingArgs.Builder.enabled());
data.addListener(message -> {
if (message.getType().equals("invalidate")) {
invalidations.addAll((List) message.getContent(StringCodec.UTF8::decodeKey).get(1));
}
});
commands.get("key1");
commands.get("key2");
assertThat(invalidations).isEmpty();
Map<String, String> keys = new HashMap<>();
keys.put("key1", "value1");
keys.put("key2", "value2");
commands.mset(keys);
Wait.untilEquals(2, invalidations::size).waitOrTimeout();
assertThat(invalidations).contains("key1", "key2");
data.close();
}
Aggregations