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

Java RedisAsyncCommands类代码示例

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

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



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

示例1: insertionRemoval

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
@Test
public void insertionRemoval() throws NumberFormatException, InterruptedException, ExecutionException {
	RedisClient redis = RedisClient.create("redis://127.0.0.1:6379");
	StatefulRedisConnection<String, String> redisConn = redis.connect();
	RedisAsyncCommands<String, String> redisCmd = redisConn.async();
	
	long iterations = 1000;
	
	for (long i = 0; i < iterations; i++) {
		redisCmd.set(String.valueOf(i), String.valueOf(i + 1));
	}
	
	for (long i = 0; i < iterations; i++) {
		long v = Long.valueOf(redisCmd.get(String.valueOf(i)).get());
		assertEquals(i + 1, v);
	}
	
	for (long i = 0; i < iterations; i++) {
		redisCmd.del(String.valueOf(i));
	}
	
	redisConn.close();
	redis.shutdown();
}
 
开发者ID:3Cores,项目名称:sostream,代码行数:25,代码来源:TestRedisLettuce.java


示例2: nodes

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected AsyncNodeSelection<K, V> nodes(Predicate<RedisClusterNode> predicate, ClusterConnectionProvider.Intent intent,
        boolean dynamic) {

    NodeSelectionSupport<RedisAsyncCommands<K, V>, ?> selection;

    StatefulRedisClusterConnectionImpl<K, V> impl = (StatefulRedisClusterConnectionImpl<K, V>) connection;
    if (dynamic) {
        selection = new DynamicNodeSelection<>(impl.getClusterDistributionChannelWriter(), predicate, intent,
                StatefulRedisConnection::async);
    } else {
        selection = new StaticNodeSelection<>(impl.getClusterDistributionChannelWriter(), predicate, intent,
                StatefulRedisConnection::async);
    }

    NodeSelectionInvocationHandler h = new NodeSelectionInvocationHandler((AbstractNodeSelection<?, ?, ?, ?>) selection,
            RedisClusterAsyncCommands.class, ASYNC);
    return (AsyncNodeSelection<K, V>) Proxy.newProxyInstance(NodeSelectionSupport.class.getClassLoader(), new Class<?>[] {
            NodeSelectionAsyncCommands.class, AsyncNodeSelection.class }, h);
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:21,代码来源:RedisAdvancedClusterAsyncCommandsImpl.java


示例3: pipelinedMessage

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
@Test(timeout = 2000)
public void pipelinedMessage() throws Exception {
    pubsub.subscribe(channel);
    assertThat(channels.take()).isEqualTo(channel);
    RedisAsyncCommands<String, String> connection = client.connectAsync();

    connection.setAutoFlushCommands(false);
    connection.publish(channel, message);
    Thread.sleep(100);

    assertThat(channels).isEmpty();
    connection.flushCommands();

    assertThat(channels.take()).isEqualTo(channel);
    assertThat(messages.take()).isEqualTo(message);

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


示例4: wrappedConnectionShouldUseWrappers

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的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


示例5: wrappedMasterSlaveConnectionShouldUseWrappers

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的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


示例6: plainConnectionShouldNotUseWrappers

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的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


示例7: requestQueueSize

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
@Test
public void requestQueueSize() {

    client.setOptions(ClientOptions.builder().requestQueueSize(10).build());

    RedisAsyncCommands<String, String> connection = client.connect().async();
    getConnectionWatchdog(connection.getStatefulConnection()).setListenOnChannelInactive(false);

    connection.quit();

    Wait.untilTrue(() -> !connection.isOpen()).waitOrTimeout();

    for (int i = 0; i < 10; i++) {
        connection.ping();
    }

    try {
        connection.ping();
        fail("missing RedisException");
    } catch (RedisException e) {
        assertThat(e).hasMessageContaining("Request queue size exceeded");
    }

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


示例8: disconnectedWithoutReconnect

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
@Test
public void disconnectedWithoutReconnect() {

    client.setOptions(ClientOptions.builder().autoReconnect(false).build());

    RedisAsyncCommands<String, String> connection = client.connect().async();

    connection.quit();
    Wait.untilTrue(() -> !connection.isOpen()).waitOrTimeout();
    try {
        connection.get(key);
    } catch (Exception e) {
        assertThat(e).isInstanceOf(RedisException.class).hasMessageContaining("not connected");
    } finally {
        connection.close();
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:18,代码来源:ClientOptionsTest.java


示例9: disconnectedRejectCommands

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
@Test
public void disconnectedRejectCommands() {

    client.setOptions(ClientOptions.builder().disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS)
            .build());

    RedisAsyncCommands<String, String> connection = client.connect().async();

    getConnectionWatchdog(connection.getStatefulConnection()).setListenOnChannelInactive(false);
    connection.quit();
    Wait.untilTrue(() -> !connection.isOpen()).waitOrTimeout();
    try {
        connection.get(key);
    } catch (Exception e) {
        assertThat(e).isInstanceOf(RedisException.class).hasMessageContaining("not connected");
    } finally {
        connection.close();
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:20,代码来源:ClientOptionsTest.java


示例10: asyncPoolPerformanceTest

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

    RedisConnectionPool<RedisAsyncCommands<String, String>> pool = client.asyncPool();
    RedisAsyncConnection<String, String> c1 = pool.allocateConnection();

    c1.ping();
    Stopwatch stopwatch = Stopwatch.createStarted();

    for (int i = 0; i < 1000; i++) {
        c1.ping();
    }

    long elapsed = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);

    log.info("asyncPoolPerformanceTest Duration: " + elapsed + "ms");

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


示例11: testUnwrap

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的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


示例12: tests

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的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


示例13: map

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
public <R> R map(Function<? super RedisAsyncCommands<String, String>, ? extends R> mapper) {
	RedisAsyncCommands<String, String> conn = pool.allocateConnection();
	try {
		return mapper.apply(conn);
	} finally {
		pool.freeConnection(conn);
	}
}
 
开发者ID:Treydone,项目名称:mandrel,代码行数:9,代码来源:RedisFrontierStore.java


示例14: with

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
public void with(Consumer<? super RedisAsyncCommands<String, String>> action) {
	RedisAsyncCommands<String, String> conn = pool.allocateConnection();
	try {
		action.accept(conn);
	} finally {
		pool.freeConnection(conn);
	}
}
 
开发者ID:Treydone,项目名称:mandrel,代码行数:9,代码来源:RedisFrontierStore.java


示例15: asyncPool

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
/**
 * Creates a connection pool for asynchronous connections. Please keep in mind to free all collections and close the pool
 * once you do not need it anymore. Requires Apache commons-pool2 dependency.
 *
 * @param codec Use this codec to encode/decode keys and values, must not be {@literal null}
 * @param maxIdle max idle connections in pool
 * @param maxActive max active connections in pool
 * @param <K> Key type
 * @param <V> Value type
 * @return a new {@link RedisConnectionPool} instance
 * @deprecated Will be removed in future versions. Use {@link ConnectionPoolSupport}.
 */
@Deprecated
public <K, V> RedisConnectionPool<RedisAsyncCommands<K, V>> asyncPool(final RedisCodec<K, V> codec, int maxIdle,
        int maxActive) {

    checkPoolDependency();
    checkForRedisURI();
    LettuceAssert.notNull(codec, "RedisCodec must not be null");

    long maxWait = makeTimeout();
    RedisConnectionPool<RedisAsyncCommands<K, V>> pool = new RedisConnectionPool<>(
            new RedisConnectionPool.RedisConnectionProvider<RedisAsyncCommands<K, V>>() {
                @Override
                public RedisAsyncCommands<K, V> createConnection() {
                    return connectStandalone(codec, redisURI, defaultTimeout()).async();
                }

                @Override
                @SuppressWarnings({ "rawtypes", "unchecked" })
                public Class<? extends RedisAsyncCommands<K, V>> getComponentType() {
                    return (Class) RedisAsyncCommands.class;
                }
            }, maxActive, maxIdle, maxWait);

    pool.addListener(closeableResources::remove);

    closeableResources.add(pool);

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


示例16: triggerSet

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
protected List<RedisFuture<?>> triggerSet(RedisAsyncCommands<String, String> connection, int iterations) {
    List<RedisFuture<?>> futures = new ArrayList<>();
    for (int i = 0; i < iterations; i++) {
        futures.add(connection.set(key(i), value(i)));
    }
    return futures;
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:8,代码来源:PipeliningTest.java


示例17: disconnectedAcceptCommands

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
@Test
public void disconnectedAcceptCommands() {

    client.setOptions(ClientOptions.builder().autoReconnect(false)
            .disconnectedBehavior(ClientOptions.DisconnectedBehavior.ACCEPT_COMMANDS).build());

    RedisAsyncCommands<String, String> connection = client.connect().async();

    connection.quit();
    Wait.untilTrue(() -> !connection.isOpen()).waitOrTimeout();
    connection.get(key);
    connection.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:14,代码来源:ClientOptionsTest.java


示例18: suspendConnection

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
private void suspendConnection(RedisClusterAsyncCommands<String, String> asyncCommands) {
    Connections.getConnectionWatchdog(((RedisAsyncCommands<?, ?>) asyncCommands).getStatefulConnection())
            .setReconnectSuspended(true);
    asyncCommands.quit();

    Wait.untilTrue(() -> !asyncCommands.isOpen()).waitOrTimeout();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:8,代码来源:RedisClusterSetupTest.java


示例19: ClusterRule

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
public ClusterRule(RedisClusterClient clusterClient, int... ports) {
    this.clusterClient = clusterClient;
    this.ports = ports;

    for (int port : ports) {
        RedisAsyncCommands<String, String> connection = clusterClient.connectToNode(
                new InetSocketAddress("localhost", port)).async();
        connectionCache.put(port, connection);
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:11,代码来源:ClusterRule.java


示例20: isStable

import com.lambdaworks.redis.api.async.RedisAsyncCommands; //导入依赖的package包/类
/**
 *
 * @return true if the cluster state is {@code ok} and there are no failing nodes
 */
public boolean isStable() {

    for (RedisAsyncCommands<String, String> commands : connectionCache.values()) {
        try {
            RedisCommands<String, String> sync = commands.getStatefulConnection().sync();
            String info = sync.clusterInfo();
            if (info != null && info.contains("cluster_state:ok")) {

                String s = sync.clusterNodes();
                Partitions parse = ClusterPartitionParser.parse(s);

                for (RedisClusterNode redisClusterNode : parse) {
                    if (redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.FAIL)
                            || redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.EVENTUAL_FAIL)
                            || redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.HANDSHAKE)) {
                        return false;
                    }
                }

            } else {
                return false;
            }
        } catch (Exception e) {
            // nothing to do
        }
    }

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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