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

The following examples show how to use io.lettuce.core.cluster.api.async.RedisAdvancedClusterAsyncCommands. 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: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();
    RedisFuture<List<String>> result = commandAsync.hkeys(params[0]);
    List<String> res = null;
    try {
        res = result.get(expireTimeLong, TimeUnit.SECONDS);
        lcr.setResult(res);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    return lcr;
}
 
Example #2
Source File: RedisSinkTaskTest.java    From kafka-connect-redis with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void before() throws InterruptedException {
  this.task = new RedisSinkTask();
  this.task.session = mock(RedisSession.class);
  this.asyncCommands = mock(RedisAdvancedClusterAsyncCommands.class, withSettings().verboseLogging());
  when(task.session.asyncCommands()).thenReturn(asyncCommands);

  RedisFuture<String> setFuture = mock(RedisFuture.class);
  when(setFuture.await(anyLong(), any(TimeUnit.class))).thenReturn(true);
  RedisFuture<Long> deleteFuture = mock(RedisFuture.class);
  when(deleteFuture.await(anyLong(), any(TimeUnit.class))).thenReturn(true);
  when(asyncCommands.mset(anyMap())).thenReturn(setFuture);
  when(asyncCommands.del(any())).thenReturn(deleteFuture);
  task.config = new RedisSinkConnectorConfig(
      ImmutableMap.of()
  );
}
 
Example #3
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 异步不需要结果
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();

    try {
        RedisFuture<String> result = commandAsync.set(params[0], params[1]);
        lcr.setResult(result);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    return lcr;
}
 
Example #4
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 只有同步
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();
    RedisFuture<Long> result = commandAsync.exists(params[0]);
    String res = "";
    try {
        res = String.valueOf(result.get(expireTimeLong, TimeUnit.SECONDS));
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    lcr.setResult(res);
    return lcr;

}
 
Example #5
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 同步异步都需要返回结果
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commands = connect.async();
    RedisFuture<String> resultSync = commands.get(params[0]);
    String result = null;
    try {
        result = resultSync.get(expireTimeLong, TimeUnit.SECONDS);
        lcr.setResult(result);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }

    return lcr;
}
 
Example #6
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 只有异步不需要返回结果

    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();

    try {
        RedisFuture<Long> result = commandAsync.del(params[0]);
        lcr.setResult(result);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }

    return lcr;
}
 
Example #7
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 只有异步不需要返回结果
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();
    try {

        RedisFuture<Boolean> result = commandAsync.expire(params[0], Long.parseLong(params[1]));
        lcr.setResult(result);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }

    return lcr;
}
 
Example #8
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 只有异步
    Map<String, String> mapValues = new HashMap<String, String>();
    for (int i = 1; i < params.length; i++) {
        mapValues.put(params[i].toString(), params[i + 1].toString());
        i++;
    }
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commands = connect.async();

    try {
        RedisFuture<String> result = commands.hmset(params[0], mapValues);
        String res = result.get(expireTimeLong, TimeUnit.SECONDS);
        lcr.setResult(result);
        lcr.setRunState(res.equals("OK"));
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    return lcr;
}
 
Example #9
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 只有同步操作
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();
    RedisFuture<Long> result = commandAsync.decr(params[0]);
    String res = "";
    try {
        res = String.valueOf(result.get(expireTimeLong, TimeUnit.SECONDS));
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    lcr.setResult(res);
    return lcr;

}
 
Example #10
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 只有同步操作
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();
    RedisFuture<Long> result = commandAsync.incr(params[0]);
    String res = "";
    try {
        res = String.valueOf(result.get(expireTimeLong, TimeUnit.SECONDS));
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    lcr.setResult(res);
    return lcr;
}
 
Example #11
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 同步异步均需返回结果
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();
    RedisFuture<String> result = commandAsync.lindex(params[0], Long.parseLong(params[1]));
    String res = "";
    try {
        res = result.get(expireTimeLong, TimeUnit.SECONDS);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    lcr.setResult(res);
    return lcr;
}
 
Example #12
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 同步异步均需返回结果
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();
    try {
        RedisFuture<Long> result = commandAsync.llen(params[0]);
        long res = result.get(expireTimeLong, TimeUnit.SECONDS);
        lcr.setResult((int) res);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setResult(0);
        lcr.setRunState(false);
    }
    return lcr;
}
 
Example #13
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 同步异步均需返回结果
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();
    RedisFuture<String> results = commandAsync.lpop(params[0]);
    try {
        String res = results.get(expireTimeLong, TimeUnit.SECONDS);
        lcr.setResult(res);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    return lcr;
}
 
Example #14
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 只有异步操作 不需要返回值
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();

    try {
        RedisFuture<Long> result = commandAsync.lpush(params[0], new String[] { params[1] });
        lcr.setResult(result);
        lcr.setRunState(true);

    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    return lcr;
}
 
Example #15
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 同步异步都要求返回结果

    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();
    try {
        RedisFuture<Long> result = commandAsync.lrem(params[0], Long.parseLong(params[1]), params[2]);
        long res = result.get(expireTimeLong, TimeUnit.SECONDS);
        lcr.setResult((int) res);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setResult(0);
        lcr.setRunState(false);
    }
    return lcr;
}
 
Example #16
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 异步不要求返回结果

    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();

    try {
        RedisFuture<String> result = commandAsync.lset(params[0], Long.parseLong(params[1]), params[2]);
        lcr.setResult(result);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    return lcr;
}
 
Example #17
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 无论同步异步都要求返回结果
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();
    RedisFuture<String> result = commandAsync.rpop(params[0]);
    try {
        String res = result.get(expireTimeLong, TimeUnit.SECONDS);
        lcr.setResult(res);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    return lcr;
}
 
Example #18
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 异步不要求返回结果
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();

    try {
        RedisFuture<Long> results = commandAsync.rpush(params[0], new String[] { params[1] });
        lcr.setResult(results);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    return lcr;
}
 
Example #19
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public Object send(String[] params) {
    // 异步不要求返回结果

    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();

    try {
        RedisFuture<Long> result = commandAsync.hdel(params[0],
                Arrays.copyOfRange(params, 1, params.length));
        lcr.setResult(result);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    return lcr;

}
 
Example #20
Source File: LettuceRedisClusterCacheManager.java    From AutoLoadCache with Apache License 2.0 5 votes vote down vote up
@Override
public void mset(Collection<MSetParam> params) {
    // 为了提升性能,开启pipeline
    this.connection.setAutoFlushCommands(false);
    RedisAdvancedClusterAsyncCommands<byte[], byte[]> asyncCommands = connection.async();
    try {
        LettuceRedisUtil.executeMSet((AbstractRedisAsyncCommands<byte[], byte[]>) asyncCommands, cacheManager, params);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    } finally {
        this.connection.flushCommands();
    }
}
 
Example #21
Source File: LettuceRedisClusterCacheManager.java    From AutoLoadCache with Apache License 2.0 5 votes vote down vote up
@Override
public void hset(byte[] key, byte[] field, byte[] value, int seconds) {
    // 为了提升性能,开启pipeline
    this.connection.setAutoFlushCommands(false);
    RedisAdvancedClusterAsyncCommands<byte[], byte[]> asyncCommands = connection.async();
    asyncCommands.hset(key, field, value);
    asyncCommands.expire(key, seconds);
    this.connection.flushCommands();
}
 
Example #22
Source File: LettuceRedisClusterCacheManager.java    From AutoLoadCache with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(Set<CacheKeyTO> keys) {
    // 为了提升性能,开启pipeline
    this.connection.setAutoFlushCommands(false);
    RedisAdvancedClusterAsyncCommands<byte[], byte[]> asyncCommands = connection.async();
    try {
        for (CacheKeyTO cacheKeyTO : keys) {
            String cacheKey = cacheKeyTO.getCacheKey();
            if (null == cacheKey || cacheKey.length() == 0) {
                continue;
            }
            if (log.isDebugEnabled()) {
                log.debug("delete cache {}", cacheKey);
            }
            String hfield = cacheKeyTO.getHfield();
            if (null == hfield || hfield.length() == 0) {
                asyncCommands.del(KEY_SERIALIZER.serialize(cacheKey));
            } else {
                asyncCommands.hdel(KEY_SERIALIZER.serialize(cacheKey), KEY_SERIALIZER.serialize(hfield));
            }
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        this.connection.flushCommands();
    }
}
 
Example #23
Source File: TracingRedisAdvancedClusterAsyncCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public TracingRedisAdvancedClusterAsyncCommands(
    RedisAdvancedClusterAsyncCommands<K, V> commands,
    TracingConfiguration tracingConfiguration) {
  this.commands = commands;
  this.helper = new TracingHelper(tracingConfiguration);
  this.tracingConfiguration = tracingConfiguration;
}
 
Example #24
Source File: TracingRedisAdvancedClusterAsyncCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public TracingRedisAdvancedClusterAsyncCommands(
    RedisAdvancedClusterAsyncCommands<K, V> commands,
    TracingConfiguration tracingConfiguration) {
  this.commands = commands;
  this.helper = new TracingHelper(tracingConfiguration);
  this.tracingConfiguration = tracingConfiguration;
}
 
Example #25
Source File: TracingRedisAdvancedClusterAsyncCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public TracingRedisAdvancedClusterAsyncCommands(
    RedisAdvancedClusterAsyncCommands<K, V> commands,
    TracingConfiguration tracingConfiguration) {
  this.commands = commands;
  this.helper = new TracingHelper(tracingConfiguration);
  this.tracingConfiguration = tracingConfiguration;
}
 
Example #26
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@Override
public Object send(String[] params) {
    // 同步与异步均需要返回结果

    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();
    RedisFuture<List<KeyValue<String, String>>> result = commandAsync.hmget(params[0],
            Arrays.copyOfRange(params, 1, params.length));
    Map<String, String> results = new HashMap<String, String>();
    List<KeyValue<String, String>> resultMap = null;
    try {
        resultMap = result.get(expireTimeLong, TimeUnit.SECONDS);
    }
    catch (Exception e) {
        lcr.setRunState(false);
        return lcr;
    }

    for (int i = 0; i < resultMap.size(); i++) {
        if (resultMap.get(i).hasValue() == true) {
            results.put(resultMap.get(i).getKey(), resultMap.get(i).getValue());
        }
    }
    lcr.setResult(results);
    lcr.setRunState(true);
    return lcr;
}
 
Example #27
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@Override
public Object send(String[] params) {
    // 同步异步均需要返回结果

    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();

    RedisFuture<List<String>> result = commandAsync.lrange(params[0], Long.parseLong(params[1]),
            Long.parseLong(params[2]));

    try {
        List<String> res = result.get(expireTimeLong, TimeUnit.SECONDS);

        if (res == null || res.isEmpty()) {
            lcr.setResult(null);
        }
        else {
            String[] resultArray = new String[res.size()];
            for (int i = 0; i < res.size(); i++) {
                resultArray[i] = res.get(i).toString();
            }
            lcr.setResult(resultArray);
        }

        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setResult(Collections.emptyList());
        lcr.setRunState(false);
    }
    return lcr;
}
 
Example #28
Source File: LettuceAsyncService.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@Override
public Object send(String[] params) {
    LettuceCommandResult lcr = new LettuceCommandResult();
    RedisAdvancedClusterAsyncCommands<String, String> commandAsync = connect.async();
    RedisFuture<Map<String, String>> result = commandAsync.hgetall(params[0]);
    try {
        Map<String, String> res = result.get(expireTimeLong, TimeUnit.SECONDS);
        lcr.setResult(res);
        lcr.setRunState(true);
    }
    catch (Exception e) {
        lcr.setRunState(false);
    }
    return lcr;
}
 
Example #29
Source File: TracingStatefulRedisClusterConnection.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisAdvancedClusterAsyncCommands<K, V> async() {
  return new TracingRedisAdvancedClusterAsyncCommands<>(connection.async(), tracingConfiguration);
}
 
Example #30
Source File: TracingStatefulRedisClusterConnection.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RedisAdvancedClusterAsyncCommands<K, V> async() {
  return new TracingRedisAdvancedClusterAsyncCommands<>(connection.async(), tracingConfiguration);
}