io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands Java Examples

The following examples show how to use io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands. 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 testAsyncCommandsClusterImplCallsWrapperFunctions() {
    @SuppressWarnings("unchecked")
    RedisClusterAsyncCommands<String, String> wrapped = (RedisClusterAsyncCommands<String, String>)
            mock(RedisClusterAsyncCommands.class);
    AsyncCommands<String> cmd = new AsyncCommandsClusterImpl<>(wrapped);
    cmd.setAutoFlushCommands(true);
    verify(wrapped, ONCE).setAutoFlushCommands(true);
    cmd.flushCommands();
    verify(wrapped).flushCommands();
    cmd.keys("pattern:*");
    verify(wrapped).keys("pattern:*");
    cmd.get("key");
    verify(wrapped).get("key");
    cmd.incr("key");
    verify(wrapped).incr("key");
    cmd.sadd("key", "v1", "v2", "v3");
    verify(wrapped).sadd("key", "v1", "v2", "v3");
    cmd.srem("key", "v1", "v2");
    verify(wrapped).srem("key", "v1", "v2");
    cmd.del("key1", "key2");
    verify(wrapped).del("key1", "key2");
    cmd.smembers("key");
    verify(wrapped).smembers("key");
    @SuppressWarnings("unchecked")
    Map<String, String> mockMap = (Map<String, String>) mock(Map.class);
    cmd.hmset("key", mockMap);
    verify(wrapped).hmset("key", mockMap);
    cmd.hgetall("key");
    verify(wrapped).hgetall("key");
    ScoredValue<String> sv1 = ScoredValue.fromNullable(1.0, "12");
    ScoredValue<String> sv2 = ScoredValue.fromNullable(1.2, "13");
    cmd.zadd("key", sv1, sv2);
    verify(wrapped).zadd("key", sv1, sv2);
    cmd.zrangeWithScores("key", 1, 100);
    verify(wrapped).zrangeWithScores("key", 1, 100);
}
 
Example #4
Source File: RedisRemoteCache.java    From curiostack with MIT License 5 votes vote down vote up
RedisRemoteCache(RedisClusterAsyncCommands<K, V> redis, String name, MeterRegistry registry) {
  this.redis = redis;
  this.name = name;

  String requests = DEFAULT_METER_ID_PREFIX.name("requests");
  success =
      registry.counter(
          requests, DEFAULT_METER_ID_PREFIX.tags("result", "success", "cache", name));
  failure =
      registry.counter(
          requests, DEFAULT_METER_ID_PREFIX.tags("result", "failure", "cache", name));
}
 
Example #5
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 #6
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 #7
Source File: RedisSession.java    From pulsar with Apache License 2.0 4 votes vote down vote up
public RedisClusterAsyncCommands<byte[], byte[]> asyncCommands() {
    return this.asyncCommands;
}
 
Example #8
Source File: AsyncCommandsClusterImpl.java    From sherlock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param commands cluster commands instance to wrap
 */
protected AsyncCommandsClusterImpl(RedisClusterAsyncCommands<K, K> commands) {
    this.commands = commands;
}
 
Example #9
Source File: RedisSession.java    From pulsar with Apache License 2.0 4 votes vote down vote up
public RedisSession(AbstractRedisClient client, StatefulConnection connection, RedisClusterAsyncCommands<byte[], byte[]> asyncCommands) {
    this.client = client;
    this.connection = connection;
    this.asyncCommands = asyncCommands;
}
 
Example #10
Source File: RedisSessionFactoryImpl.java    From kafka-connect-redis with Apache License 2.0 4 votes vote down vote up
public RedisClusterAsyncCommands<byte[], byte[]> asyncCommands() {
  return this.asyncCommands;
}
 
Example #11
Source File: RedisSessionFactoryImpl.java    From kafka-connect-redis with Apache License 2.0 4 votes vote down vote up
RedisSessionImpl(AbstractRedisClient client, StatefulConnection connection, RedisClusterAsyncCommands<byte[], byte[]> asyncCommands, RedisConnectorConfig config) {
  this.client = client;
  this.connection = connection;
  this.asyncCommands = asyncCommands;
  this.config = config;
}
 
Example #12
Source File: SinkOperation.java    From kafka-connect-redis with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(RedisClusterAsyncCommands<byte[], byte[]> asyncCommands) throws InterruptedException {
  log.debug("execute() - Calling mset with {} value(s)", this.sets.size());
  RedisFuture<?> future = asyncCommands.mset(this.sets);
  wait(future);
}
 
Example #13
Source File: TracingRedisAdvancedClusterAsyncCommands.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisClusterAsyncCommands<K, V> getConnection(String host, int port) {
  return new TracingRedisAsyncCommands<>(commands.getStatefulConnection()
      .getConnection(host, port).async(), tracingConfiguration);
}
 
Example #14
Source File: TracingRedisAdvancedClusterAsyncCommands.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisClusterAsyncCommands<K, V> getConnection(String nodeId) {
  return new TracingRedisAsyncCommands<>(commands.getStatefulConnection()
      .getConnection(nodeId).async(), tracingConfiguration);
}
 
Example #15
Source File: TracingRedisAdvancedClusterAsyncCommands.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisClusterAsyncCommands<K, V> getConnection(String host, int port) {
  return new TracingRedisAsyncCommands<>(commands.getStatefulConnection()
      .getConnection(host, port).async(), tracingConfiguration);
}
 
Example #16
Source File: TracingRedisAdvancedClusterAsyncCommands.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisClusterAsyncCommands<K, V> getConnection(String nodeId) {
  return new TracingRedisAsyncCommands<>(commands.getStatefulConnection()
      .getConnection(nodeId).async(), tracingConfiguration);
}
 
Example #17
Source File: TracingRedisAdvancedClusterAsyncCommands.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisClusterAsyncCommands<K, V> getConnection(String host, int port) {
  return new TracingRedisAsyncCommands<>(commands.getStatefulConnection()
      .getConnection(host, port).async(), tracingConfiguration);
}
 
Example #18
Source File: TracingRedisAdvancedClusterAsyncCommands.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisClusterAsyncCommands<K, V> getConnection(String nodeId) {
  return new TracingRedisAsyncCommands<>(commands.getStatefulConnection()
      .getConnection(nodeId).async(), tracingConfiguration);
}
 
Example #19
Source File: SinkOperation.java    From kafka-connect-redis with Apache License 2.0 2 votes vote down vote up
@Override
public void execute(RedisClusterAsyncCommands<byte[], byte[]> asyncCommands) {

}
 
Example #20
Source File: SinkOperation.java    From kafka-connect-redis with Apache License 2.0 votes vote down vote up
public abstract void execute(RedisClusterAsyncCommands<byte[], byte[]> asyncCommands) throws InterruptedException; 
Example #21
Source File: RedisSession.java    From kafka-connect-redis with Apache License 2.0 votes vote down vote up
RedisClusterAsyncCommands<byte[], byte[]> asyncCommands();