• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java RedisCommands类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.lambdaworks.redis.api.sync.RedisCommands的典型用法代码示例。如果您正苦于以下问题:Java RedisCommands类的具体用法?Java RedisCommands怎么用?Java RedisCommands使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RedisCommands类属于com.lambdaworks.redis.api.sync包,在下文中一共展示了RedisCommands类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: commandIsExecutedOnce

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void commandIsExecutedOnce() {

    RedisCommands<String, String> connection = client.connect().sync();

    connection.set(key, "1");
    connection.incr(key);
    assertThat(connection.get(key)).isEqualTo("2");

    connection.incr(key);
    assertThat(connection.get(key)).isEqualTo("3");

    connection.incr(key);
    assertThat(connection.get(key)).isEqualTo("4");

    connection.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:18,代码来源:AtMostOnceTest.java


示例2: commandFailsDuringDecode

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void commandFailsDuringDecode() {

    RedisCommands<String, String> connection = client.connect().sync();
    RedisChannelWriter<String, String> channelWriter = getRedisChannelHandler(connection).getChannelWriter();
    RedisCommands<String, String> verificationConnection = client.connect().sync();

    connection.set(key, "1");

    AsyncCommand<String, String, String> command = new AsyncCommand<>(new Command<>(CommandType.INCR, new StatusOutput<>(
            CODEC), new CommandArgs<>(CODEC).addKey(key)));

    channelWriter.write(command);

    assertThat(command.await(2, TimeUnit.SECONDS)).isTrue();
    assertThat(command.isCancelled()).isFalse();
    assertThat(getException(command)).isInstanceOf(IllegalStateException.class);

    assertThat(verificationConnection.get(key)).isEqualTo("2");
    assertThat(connection.get(key)).isEqualTo("2");

    connection.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:24,代码来源:AtMostOnceTest.java


示例3: commandIsExecutedOnce

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void commandIsExecutedOnce() throws Exception {

    RedisCommands<String, String> connection = client.connect().sync();

    connection.set(key, "1");
    connection.incr(key);
    assertThat(connection.get(key)).isEqualTo("2");

    connection.incr(key);
    assertThat(connection.get(key)).isEqualTo("3");

    connection.incr(key);
    assertThat(connection.get(key)).isEqualTo("4");

    connection.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:18,代码来源:AtLeastOnceTest.java


示例4: commandFailsDuringDecode

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void commandFailsDuringDecode() throws Exception {

    RedisCommands<String, String> connection = client.connect().sync();
    RedisChannelWriter<String, String> channelWriter = getRedisChannelHandler(connection).getChannelWriter();
    RedisCommands<String, String> verificationConnection = client.connect().sync();

    connection.set(key, "1");

    AsyncCommand<String, String, String> command = new AsyncCommand(new Command<>(CommandType.INCR, new StatusOutput<>(
            CODEC), new CommandArgs<>(CODEC).addKey(key)));

    channelWriter.write(command);

    assertThat(command.await(2, TimeUnit.SECONDS)).isTrue();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isTrue();
    assertThat(getException(command)).isInstanceOf(IllegalStateException.class);

    assertThat(verificationConnection.get(key)).isEqualTo("2");
    assertThat(connection.get(key)).isEqualTo("2");

    connection.close();
    verificationConnection.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:26,代码来源:AtLeastOnceTest.java


示例5: hasMaster

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
/**
 * Check if a master runs on any of the given ports.
 *
 * @param redisPorts
 * @return
 */
public boolean hasMaster(int... redisPorts) {

    Map<Integer, RedisCommands<String, String>> connections = new HashMap<>();
    for (int redisPort : redisPorts) {
        connections.put(redisPort,
                redisClient.connect(RedisURI.Builder.redis(TestSettings.hostAddr(), redisPort).build()).sync());
    }

    try {
        Integer masterPort = getMasterPort(connections);
        if (masterPort != null) {
            return true;
        }
    } finally {
        for (RedisCommands<String, String> commands : connections.values()) {
            commands.close();
        }
    }

    return false;
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:28,代码来源:SentinelRule.java


示例6: genericPoolUsingWrappingShouldPropagateExceptionsCorrectly

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void genericPoolUsingWrappingShouldPropagateExceptionsCorrectly() throws Exception {

    GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
            () -> client.connect(), new GenericObjectPoolConfig());

    StatefulRedisConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();
    sync.set(key, value);

    try {
        sync.hgetall(key);
        fail("Missing RedisCommandExecutionException");
    } catch (RedisCommandExecutionException e) {
        assertThat(e).hasMessageContaining("WRONGTYPE");
    }

    sync.close();
    pool.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:21,代码来源:ConnectionPoolSupportTest.java


示例7: wrappedConnectionShouldUseWrappers

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void wrappedConnectionShouldUseWrappers() throws Exception {

    GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
            () -> client.connect(), new GenericObjectPoolConfig());

    StatefulRedisConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();

    assertThat(connection).isInstanceOf(StatefulRedisConnection.class).isNotInstanceOf(
            StatefulRedisClusterConnectionImpl.class);
    assertThat(Proxy.isProxyClass(connection.getClass())).isTrue();

    assertThat(sync).isInstanceOf(RedisCommands.class);
    assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class).isNotInstanceOf(RedisAsyncCommandsImpl.class);
    assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class).isNotInstanceOf(
            RedisReactiveCommandsImpl.class);
    assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class)
            .isNotInstanceOf(StatefulRedisConnectionImpl.class).isSameAs(connection);

    sync.close();
    pool.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:24,代码来源:ConnectionPoolSupportTest.java


示例8: wrappedMasterSlaveConnectionShouldUseWrappers

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void wrappedMasterSlaveConnectionShouldUseWrappers() throws Exception {

    GenericObjectPool<StatefulRedisMasterSlaveConnection<String, String>> pool = ConnectionPoolSupport
            .createGenericObjectPool(() -> MasterSlave.connect(client, new StringCodec(), RedisURI.create(host, port)),
                    new GenericObjectPoolConfig());

    StatefulRedisMasterSlaveConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();

    assertThat(connection).isInstanceOf(StatefulRedisMasterSlaveConnection.class);
    assertThat(Proxy.isProxyClass(connection.getClass())).isTrue();

    assertThat(sync).isInstanceOf(RedisCommands.class);
    assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class).isNotInstanceOf(RedisAsyncCommandsImpl.class);
    assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class).isNotInstanceOf(
            RedisReactiveCommandsImpl.class);
    assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class)
            .isNotInstanceOf(StatefulRedisConnectionImpl.class).isSameAs(connection);

    sync.close();
    pool.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:24,代码来源:ConnectionPoolSupportTest.java


示例9: plainConnectionShouldNotUseWrappers

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void plainConnectionShouldNotUseWrappers() throws Exception {

    GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
            () -> client.connect(), new GenericObjectPoolConfig(), false);

    StatefulRedisConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();

    assertThat(connection).isInstanceOf(StatefulRedisConnection.class).isNotInstanceOf(
            StatefulRedisClusterConnectionImpl.class);
    assertThat(Proxy.isProxyClass(connection.getClass())).isFalse();

    assertThat(sync).isInstanceOf(RedisCommands.class);
    assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class).isInstanceOf(RedisAsyncCommandsImpl.class);
    assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class).isInstanceOf(
            RedisReactiveCommandsImpl.class);
    assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class).isInstanceOf(
            StatefulRedisConnectionImpl.class);

    pool.returnObject(connection);
    pool.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:24,代码来源:ConnectionPoolSupportTest.java


示例10: wrappedObjectClosedAfterReturn

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void wrappedObjectClosedAfterReturn() throws Exception {

    GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
            () -> client.connect(), new GenericObjectPoolConfig(), true);

    StatefulRedisConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();
    sync.ping();
    sync.close();

    try {
        connection.isMulti();
        fail("Missing RedisException");
    } catch (RedisException e) {
        assertThat(e).hasMessageContaining("deallocated");
    }

    pool.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:21,代码来源:ConnectionPoolSupportTest.java


示例11: tryWithResourcesReturnsConnectionToPool

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void tryWithResourcesReturnsConnectionToPool() throws Exception {

    GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
            () -> client.connect(), new GenericObjectPoolConfig());

    StatefulRedisConnection<String, String> usedConnection = null;
    try (StatefulRedisConnection<String, String> connection = pool.borrowObject()) {

        RedisCommands<String, String> sync = connection.sync();
        sync.ping();

        usedConnection = connection;
    }

    try {
        usedConnection.isMulti();
        fail("Missing RedisException");
    } catch (RedisException e) {
        assertThat(e).hasMessageContaining("deallocated");
    }

    pool.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:25,代码来源:ConnectionPoolSupportTest.java


示例12: tryWithResourcesReturnsSoftRefConnectionToPool

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void tryWithResourcesReturnsSoftRefConnectionToPool() throws Exception {

    SoftReferenceObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
            .createSoftReferenceObjectPool(() -> client.connect());

    StatefulRedisConnection<String, String> usedConnection = null;
    try (StatefulRedisConnection<String, String> connection = pool.borrowObject()) {

        RedisCommands<String, String> sync = connection.sync();
        sync.ping();

        usedConnection = connection;
    }

    try {
        usedConnection.isMulti();
        fail("Missing RedisException");
    } catch (RedisException e) {
        assertThat(e).hasMessageContaining("deallocated");
    }

    pool.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:25,代码来源:ConnectionPoolSupportTest.java


示例13: testPooling

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void testPooling() throws Exception {
    final RedisConnectionPool<RedisCommands<String, String>> pool = client.pool();

    assertThat(pool.getNumActive()).isEqualTo(0);
    assertThat(pool.getNumIdle()).isEqualTo(0);

    new WithConnection<RedisCommands<String, String>>(pool) {

        @Override
        protected void run(RedisCommands<String, String> connection) {
            connection.set("key", "value");
            String result = connection.get("key");
            assertThat(result).isEqualTo("value");

            assertThat(pool.getNumActive()).isEqualTo(1);
            assertThat(pool.getNumIdle()).isEqualTo(0);
        }
    };

    assertThat(pool.getNumActive()).isEqualTo(0);
    assertThat(pool.getNumIdle()).isEqualTo(1);

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


示例14: testPoolingWithException

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void testPoolingWithException() throws Exception {
    final RedisConnectionPool<RedisCommands<String, String>> pool = client.pool();

    assertThat(pool.getNumActive()).isEqualTo(0);
    assertThat(pool.getNumIdle()).isEqualTo(0);

    try {
        new WithConnection<RedisCommands<String, String>>(pool) {

            @Override
            protected void run(RedisCommands<String, String> connection) {
                connection.set("key", "value");
                throw new IllegalStateException("test");
            }
        };

        fail("Missing Exception");
    } catch (Exception e) {
    }

    assertThat(pool.getNumActive()).isEqualTo(0);
    assertThat(pool.getNumIdle()).isEqualTo(1);

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


示例15: pingBeforeConnectWithAuthentication

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void pingBeforeConnectWithAuthentication() {

    new WithPasswordRequired() {
        @Override
        protected void run(RedisClient client) {

            client.setOptions(ClientOptions.builder().pingBeforeActivateConnection(true).build());
            RedisURI redisURI = RedisURI.Builder.redis(host, port).withPassword(passwd).build();

            RedisCommands<String, String> connection = client.connect(redisURI).sync();

            try {
                String result = connection.info();
                assertThat(result).contains("memory");
            } finally {
                connection.close();
            }

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


示例16: pingBeforeConnectWithSslAndAuthentication

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void pingBeforeConnectWithSslAndAuthentication() {

    new WithPasswordRequired() {
        @Override
        protected void run(RedisClient client) {

            client.setOptions(ClientOptions.builder().pingBeforeActivateConnection(true).build());
            RedisURI redisURI = RedisURI.Builder.redis(host, 6443).withPassword(passwd).withVerifyPeer(false).withSsl(true)
                    .build();

            RedisCommands<String, String> connection = client.connect(redisURI).sync();

            try {
                String result = connection.info();
                assertThat(result).contains("memory");
            } finally {
                connection.close();
            }

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


示例17: twoConnections

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void twoConnections() throws Exception {

    RedisConnectionPool<RedisCommands<String, String>> pool = client.pool();
    RedisCommands<String, String> c1 = pool.allocateConnection();
    RedisConnection<String, String> c2 = pool.allocateConnection();

    String result1 = c1.ping();
    String result2 = c2.ping();
    assertThat(result1).isEqualTo("PONG");
    assertThat(result2).isEqualTo("PONG");

    c1.close();
    c2.close();
    pool.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:17,代码来源:PoolConnectionTest.java


示例18: connectionCloseDoesNotClose

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void connectionCloseDoesNotClose() throws Exception {
    RedisConnectionPool<RedisCommands<String, String>> pool = client.pool();
    RedisConnection<String, String> c1 = pool.allocateConnection();
    c1.close();
    RedisConnection<String, String> actualConnection1 = assertConnectionStillThere(c1);

    RedisConnection<String, String> c2 = pool.allocateConnection();
    assertThat(c2).isSameAs(c1);

    RedisConnection<String, String> actualConnection2 = assertConnectionStillThere(c2);
    assertThat(actualConnection1).isSameAs(actualConnection2);

    c2.close();
    pool.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:17,代码来源:PoolConnectionTest.java


示例19: testUnwrap

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
private void testUnwrap(AbstractRedisClient client) {
    Assert.assertTrue(cache.unwrap(AbstractRedisClient.class) instanceof AbstractRedisClient);
    if (client instanceof RedisClient) {
        Assert.assertTrue(cache.unwrap(RedisClient.class) instanceof RedisClient);
        Assert.assertTrue(cache.unwrap(RedisCommands.class) instanceof RedisCommands);
        Assert.assertTrue(cache.unwrap(RedisAsyncCommands.class) instanceof RedisAsyncCommands);
        Assert.assertTrue(cache.unwrap(RedisReactiveCommands.class) instanceof RedisReactiveCommands);
    } else {
        Assert.assertTrue(cache.unwrap(RedisClusterClient.class) instanceof RedisClusterClient);
        Assert.assertTrue(cache.unwrap(RedisClusterCommands.class) instanceof RedisClusterCommands);
        Assert.assertTrue(cache.unwrap(RedisClusterAsyncCommands.class) instanceof RedisClusterAsyncCommands);
        Assert.assertTrue(cache.unwrap(RedisClusterReactiveCommands.class) instanceof RedisClusterReactiveCommands);
    }
}
 
开发者ID:alibaba,项目名称:jetcache,代码行数:15,代码来源:RedisLettuceCacheTest.java


示例20: tests

import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void tests() throws Exception {
    if (RedisLettuceCacheTest.checkOS()) {
        System.setProperty("spring.profiles.active", "redislettuce4-cluster");
    } else {
        System.setProperty("spring.profiles.active", "redislettuce4");
    }
    context = SpringApplication.run(RedisLettuce4StarterTest.class);
    doTest();
    A bean = context.getBean(A.class);
    bean.test();

    RedisClient t1 = (RedisClient) context.getBean("defaultClient");
    RedisClient t2 = (RedisClient) context.getBean("a1Client");
    Assert.assertNotNull(t1);
    Assert.assertNotNull(t2);
    Assert.assertNotSame(t1, t2);

    AutoConfigureBeans acb = context.getBean(AutoConfigureBeans.class);

    String key = "remote.A1";
    Assert.assertTrue(new Lettuce4Factory(acb, key, StatefulRedisConnection.class).getObject() instanceof StatefulRedisConnection);
    Assert.assertTrue(new Lettuce4Factory(acb, key, RedisCommands.class).getObject() instanceof RedisCommands);
    Assert.assertTrue(new Lettuce4Factory(acb, key, RedisAsyncCommands.class).getObject() instanceof RedisAsyncCommands);
    Assert.assertTrue(new Lettuce4Factory(acb, key, RedisReactiveCommands.class).getObject() instanceof RedisReactiveCommands);

    if (RedisLettuceCacheTest.checkOS()) {
        key = "remote.A2";
        Assert.assertTrue(new Lettuce4Factory(acb, key , RedisClusterClient.class).getObject() instanceof RedisClusterClient);
        Assert.assertTrue(new Lettuce4Factory(acb, key , RedisClusterCommands.class).getObject() instanceof RedisClusterCommands);
        Assert.assertTrue(new Lettuce4Factory(acb, key , RedisClusterAsyncCommands.class).getObject() instanceof RedisClusterAsyncCommands);
        Assert.assertTrue(new Lettuce4Factory(acb, key , RedisClusterReactiveCommands.class).getObject() instanceof RedisClusterReactiveCommands);
    }
}
 
开发者ID:alibaba,项目名称:jetcache,代码行数:35,代码来源:RedisLettuce4StarterTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RichSpoutBatchExecutor类代码示例发布时间:2022-05-22
下一篇:
Java PhotoViewAttacher类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap