当前位置: 首页>>代码示例>>Java>>正文


Java StatefulRedisConnection.dispatch方法代码示例

本文整理汇总了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);
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:15,代码来源:MasterSlaveChannelWriter.java

示例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();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:41,代码来源:ClientOptionsTest.java

示例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();
        }
    };

}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:50,代码来源:ClientOptionsTest.java


注:本文中的com.lambdaworks.redis.api.StatefulRedisConnection.dispatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。