io.lettuce.core.cluster.api.sync.RedisClusterCommands Java Examples

The following examples show how to use io.lettuce.core.cluster.api.sync.RedisClusterCommands. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisLettuceCache.java    From jetcache with Apache License 2.0 6 votes vote down vote up
@Override
public <T> T unwrap(Class<T> clazz) {
    Objects.requireNonNull(clazz);
    if (AbstractRedisClient.class.isAssignableFrom(clazz)) {
        return (T) client;
    } else if (RedisClusterCommands.class.isAssignableFrom(clazz)) {
        // RedisCommands extends RedisClusterCommands
        return (T) stringCommands;
    } else if (RedisClusterAsyncCommands.class.isAssignableFrom(clazz)) {
        // RedisAsyncCommands extends RedisClusterAsyncCommands
        return (T) stringAsyncCommands;
    } else if (RedisClusterReactiveCommands.class.isAssignableFrom(clazz)) {
        // RedisReactiveCommands extends RedisClusterReactiveCommands
        return (T) lettuceConnectionManager.reactiveCommands(client);
    }
    throw new IllegalArgumentException(clazz.getName());
}
 
Example #2
Source File: LettuceFactory.java    From jetcache with Apache License 2.0 6 votes vote down vote up
public LettuceFactory(String key, Class<?> clazz) {
    this.clazz = clazz;
    if (AbstractRedisClient.class.isAssignableFrom(clazz)) {
        key += ".client";
    } else if (StatefulConnection.class.isAssignableFrom(clazz)) {
        key += ".connection";
    } else if (RedisClusterCommands.class.isAssignableFrom(clazz)) {
        // RedisCommands extends RedisClusterCommands
        key += ".commands";
    } else if (RedisClusterAsyncCommands.class.isAssignableFrom(clazz)) {
        // RedisAsyncCommands extends RedisClusterAsyncCommands
        key += ".asyncCommands";
    } else if (RedisClusterReactiveCommands.class.isAssignableFrom(clazz)) {
        // RedisReactiveCommands extends RedisClusterReactiveCommands
        key += ".reactiveCommands";
    } else {
        throw new IllegalArgumentException(clazz.getName());
    }
    this.key = key;
}
 
Example #3
Source File: WrapperTests.java    From sherlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSyncCommandsClusterImplCallsWrapperFunctions() {
    @SuppressWarnings("unchecked")
    RedisClusterCommands<String, String> wrapped = (RedisClusterCommands<String, String>)
            mock(RedisClusterCommands.class);
    SyncCommands<String> cmd = new SyncCommandsClusterImpl<>(wrapped);
    cmd.incr("key");
    verify(wrapped).incr("key");
    cmd.smembers("key");
    verify(wrapped).smembers("key");
    cmd.hgetall("key");
    verify(wrapped).hgetall("key");
    cmd.zadd("key", 1.0, "value");
    verify(wrapped).zadd("key", 1.0, "value");
    cmd.zrem("key", "v1", "v2");
    verify(wrapped).zrem("key", "v1", "v2");
    cmd.del("key1", "key2");
    verify(wrapped).del("key1", "key2");
    cmd.zrangeWithScores("key", 0, 100);
    verify(wrapped).zrangeWithScores("key", 0, 100);
    @SuppressWarnings("unchecked")
    Range<Double> range = (Range<Double>) mock(Range.class);
    cmd.zcount("key", range);
    verify(wrapped).zcount("key", range);
    cmd.eval("script", ScriptOutputType.MULTI, new String[]{"key1", "key2"}, "v1", "v2");
    verify(wrapped).eval("script", ScriptOutputType.MULTI, new String[]{"key1", "key2"}, "v1", "v2");
}
 
Example #4
Source File: RedisLettuceCacheTest.java    From jetcache with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #5
Source File: RedisLettuceStarterTest.java    From jetcache with Apache License 2.0 5 votes vote down vote up
@Test
public void tests() throws Exception {
    if (RedisLettuceCacheTest.checkOS()) {
        System.setProperty("spring.profiles.active", "redislettuce-cluster");
    } else {
        System.setProperty("spring.profiles.active", "redislettuce");
    }
    context = SpringApplication.run(RedisLettuceStarterTest.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 LettuceFactory(acb, key, StatefulRedisConnection.class).getObject() instanceof StatefulRedisConnection);
    Assert.assertTrue(new LettuceFactory(acb, key, RedisCommands.class).getObject() instanceof RedisCommands);
    Assert.assertTrue(new LettuceFactory(acb, key, RedisAsyncCommands.class).getObject() instanceof RedisAsyncCommands);
    Assert.assertTrue(new LettuceFactory(acb, key, RedisReactiveCommands.class).getObject() instanceof RedisReactiveCommands);

    if (RedisLettuceCacheTest.checkOS()) {
        key = "remote.A2";
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterClient.class).getObject() instanceof RedisClusterClient);
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterCommands.class).getObject() instanceof RedisClusterCommands);
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterAsyncCommands.class).getObject() instanceof RedisClusterAsyncCommands);
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterReactiveCommands.class).getObject() instanceof RedisClusterReactiveCommands);

        key = "remote.A2_slave";
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterClient.class).getObject() instanceof RedisClusterClient);
    }
}
 
Example #6
Source File: SyncCommandsClusterImpl.java    From sherlock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param commands cluster commands to wrap
 */
protected SyncCommandsClusterImpl(RedisClusterCommands<K, K> commands) {
    this.commands = commands;
}
 
Example #7
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisClusterCommands<K, V> getConnection(String nodeId) {
  return new TracingRedisCommands<>(commands.getStatefulConnection()
      .getConnection(nodeId).sync(),
      tracingConfiguration);
}
 
Example #8
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisClusterCommands<K, V> getConnection(String host, int port) {
  return new TracingRedisCommands<>(commands.getStatefulConnection()
      .getConnection(host, port).sync(),
      tracingConfiguration);
}
 
Example #9
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisClusterCommands<K, V> getConnection(String nodeId) {
  return new TracingRedisCommands<>(commands.getStatefulConnection()
      .getConnection(nodeId).sync(),
      tracingConfiguration);
}
 
Example #10
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisClusterCommands<K, V> getConnection(String host, int port) {
  return new TracingRedisCommands<>(commands.getStatefulConnection()
      .getConnection(host, port).sync(),
      tracingConfiguration);
}
 
Example #11
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisClusterCommands<K, V> getConnection(String nodeId) {
  return new TracingRedisCommands<>(commands.getStatefulConnection()
      .getConnection(nodeId).sync(),
      tracingConfiguration);
}
 
Example #12
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisClusterCommands<K, V> getConnection(String host, int port) {
  return new TracingRedisCommands<>(commands.getStatefulConnection()
      .getConnection(host, port).sync(),
      tracingConfiguration);
}