本文整理汇总了Java中com.lambdaworks.redis.api.StatefulRedisConnection.dispatch方法的典型用法代码示例。如果您正苦于以下问题:Java StatefulRedisConnection.dispatch方法的具体用法?Java StatefulRedisConnection.dispatch怎么用?Java StatefulRedisConnection.dispatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lambdaworks.redis.api.StatefulRedisConnection
的用法示例。
在下文中一共展示了StatefulRedisConnection.dispatch方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的package包/类
@Override
public <T, C extends RedisCommand<K, V, T>> C write(C command) {
LettuceAssert.notNull(command, "Command must not be null");
if (closed) {
throw new RedisException("Connection is closed");
}
MasterSlaveConnectionProvider.Intent intent = getIntent(command.getType());
StatefulRedisConnection<K, V> connection = masterSlaveConnectionProvider.getConnection(intent);
return connection.dispatch(command);
}
示例2: pingBeforeConnectWithQueuedCommandsAndReconnect
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的package包/类
@Test(timeout = 10000)
public void pingBeforeConnectWithQueuedCommandsAndReconnect() throws Exception {
StatefulRedisConnection<String, String> controlConnection = client.connect();
client.setOptions(new ClientOptions.Builder().pingBeforeActivateConnection(true).build());
Utf8StringCodec codec = new Utf8StringCodec();
StatefulRedisConnection<String, String> redisConnection = client.connect(RedisURI.create("redis://localhost:6479/5"));
redisConnection.async().set("key1", "value1");
redisConnection.async().set("key2", "value2");
RedisFuture<String> sleep = controlConnection.dispatch(new AsyncCommand<>(new Command<>(CommandType.DEBUG,
new StatusOutput<>(codec), new CommandArgs<>(codec).add("SLEEP").add(2))));
sleep.await(100, TimeUnit.MILLISECONDS);
Channel channel = getChannel(redisConnection);
ConnectionWatchdog connectionWatchdog = getConnectionWatchdog(redisConnection);
connectionWatchdog.setReconnectSuspended(true);
channel.close().get();
sleep.get();
redisConnection.async().get(key).cancel(true);
RedisFuture<String> getFuture1 = redisConnection.async().get("key1");
RedisFuture<String> getFuture2 = redisConnection.async().get("key2");
getFuture1.await(100, TimeUnit.MILLISECONDS);
connectionWatchdog.setReconnectSuspended(false);
connectionWatchdog.scheduleReconnect();
assertThat(getFuture1.get()).isEqualTo("value1");
assertThat(getFuture2.get()).isEqualTo("value2");
controlConnection.close();
redisConnection.close();
}
示例3: authenticatedPingBeforeConnectWithQueuedCommandsAndReconnect
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的package包/类
@Test(timeout = 10000)
public void authenticatedPingBeforeConnectWithQueuedCommandsAndReconnect() {
new WithPasswordRequired() {
@Override
protected void run(RedisClient client) throws Exception {
RedisURI redisURI = RedisURI.Builder.redis(host, port).withPassword(passwd).withDatabase(5).build();
StatefulRedisConnection<String, String> controlConnection = client.connect(redisURI);
client.setOptions(new ClientOptions.Builder().pingBeforeActivateConnection(true).build());
Utf8StringCodec codec = new Utf8StringCodec();
StatefulRedisConnection<String, String> redisConnection = client.connect(redisURI);
redisConnection.async().set("key1", "value1");
redisConnection.async().set("key2", "value2");
RedisFuture<String> sleep = controlConnection.dispatch(new AsyncCommand<>(new Command<>(CommandType.DEBUG,
new StatusOutput<>(codec), new CommandArgs<>(codec).add("SLEEP").add(2))));
sleep.await(100, TimeUnit.MILLISECONDS);
Channel channel = getChannel(redisConnection);
ConnectionWatchdog connectionWatchdog = getConnectionWatchdog(redisConnection);
connectionWatchdog.setReconnectSuspended(true);
channel.close().get();
sleep.get();
redisConnection.async().get(key).cancel(true);
RedisFuture<String> getFuture1 = redisConnection.async().get("key1");
RedisFuture<String> getFuture2 = redisConnection.async().get("key2");
getFuture1.await(100, TimeUnit.MILLISECONDS);
connectionWatchdog.setReconnectSuspended(false);
connectionWatchdog.scheduleReconnect();
assertThat(getFuture1.get()).isEqualTo("value1");
assertThat(getFuture2.get()).isEqualTo("value2");
controlConnection.close();
redisConnection.close();
}
};
}