com.lambdaworks.redis.RedisFuture Java Examples

The following examples show how to use com.lambdaworks.redis.RedisFuture. 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: RedisGetSetClient.java    From moleculer-java with MIT License 5 votes vote down vote up
private final CompletionStage<Object> clean(RedisFuture<KeyScanCursor<byte[]>> future, ScanArgs args,
		String match) {
	return future.thenCompose(keyScanCursor -> {
		List<byte[]> keys = keyScanCursor.getKeys();
		if (keys == null || keys.isEmpty()) {
			return CompletableFuture.completedFuture(keyScanCursor);
		}
		if (match != null) {
			Iterator<byte[]> i = keys.iterator();
			while (i.hasNext()) {
				if (!Matcher.matches(new String(i.next(), StandardCharsets.UTF_8), match)) {
					i.remove();
				}
			}
		}
		if (keys.isEmpty()) {
			return CompletableFuture.completedFuture(keyScanCursor);
		}
		byte[][] array = new byte[keys.size()][];
		keys.toArray(array);
		return client.del(array).thenApply(nul -> keyScanCursor);
	}).thenApply(keyScanCursor -> {
		if (((KeyScanCursor<byte[]>) keyScanCursor).isFinished()) {
			return null;
		}
		return ((KeyScanCursor<byte[]>) keyScanCursor).getCursor();
	}).thenCompose(currentCursor -> {
		if (currentCursor == null) {
			return CompletableFuture.completedFuture(null);
		}
		return clean(new ScanCursor((String) currentCursor, false), args, match);
	});
}
 
Example #2
Source File: SyncAsyncApiConvergenceTest.java    From spinach with Apache License 2.0 5 votes vote down vote up
@Test
public void testSameResultType() throws Exception {
    Method method = asyncClass.getMethod(this.method.getName(), this.method.getParameterTypes());
    Class<?> returnType = method.getReturnType();

    if (returnType.equals(RedisFuture.class)) {
        ParameterizedType genericReturnType = (ParameterizedType) method.getGenericReturnType();
        Type[] actualTypeArguments = genericReturnType.getActualTypeArguments();

        if (actualTypeArguments[0] instanceof TypeVariable) {

            assertThat(Object.class).isEqualTo(this.method.getReturnType());
            return;
        }

        if (actualTypeArguments[0] instanceof ParameterizedType) {

            ParameterizedType parameterizedType = (ParameterizedType) actualTypeArguments[0];
            returnType = (Class<?>) parameterizedType.getRawType();
        } else if (actualTypeArguments[0] instanceof GenericArrayType) {

            GenericArrayType arrayType = (GenericArrayType) actualTypeArguments[0];
            returnType = Array.newInstance((Class<?>) arrayType.getGenericComponentType(), 0).getClass();
        } else {
            returnType = (Class<?>) actualTypeArguments[0];
        }
    }

    Class<?> expectedType = getType(this.method.getReturnType());
    returnType = getType(returnType);

    assertThat(returnType).describedAs(this.method.toString()).isEqualTo(expectedType);

}
 
Example #3
Source File: RedisTransactionLogWritterImpl.java    From EasyTransaction with Apache License 2.0 5 votes vote down vote up
@Override
public void appendTransLog(String appId, String busCode, long trxId, List<Content> newOrderedContent,
		boolean finished) {

	String transId = ObjectDigestUtil.byteArrayToHexString(idCodec.getTransIdByte(new TransactionId(appId, busCode, trxId)));
	RedisFuture<Long> zadd = null;
	RedisFuture<Long> rpush = null;
	RedisFuture<Long> zrem = null;
	RedisFuture<Long> del = null;
	if (!finished) {
		zadd = async.zadd(keyPrefix + appId, (double) System.currentTimeMillis(), (keyPrefix + transId).getBytes(StandardCharsets.UTF_8));
		//εΊεˆ—εŒ–
		byte[][] array = newOrderedContent.stream().map(objectSerializer::serialization).toArray(byte[][]::new);
		rpush = async.rpush(keyPrefix + transId, array);
	} else {
		zrem = async.zrem(keyPrefix + appId, (keyPrefix + transId).getBytes(StandardCharsets.UTF_8));
		del = async.del(keyPrefix + transId);
	}

	try {
		if (zadd != null) {
			zadd.get();
		}
		if (rpush != null) {
			rpush.get();
		}
		if (zrem != null) {
			zrem.get();
		}
		if (del != null) {
			del.get();
		}
	} catch (InterruptedException | ExecutionException e) {
		throw new RuntimeException(e);
	}
}
 
Example #4
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> clusterNodes() {
    return dispatch(commandBuilder.clusterNodes());
}
 
Example #5
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> addjob(K queue, V job, long commandTimeout, TimeUnit timeUnit) {
    return dispatch(commandBuilder.addjob(queue, job, commandTimeout, timeUnit, null));
}
 
Example #6
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<Long> ackjob(String... jobIds) {
    return dispatch(commandBuilder.ackjob(jobIds));
}
 
Example #7
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<Long> clientKill(KillArgs killArgs) {
    return dispatch(commandBuilder.clientKill(killArgs));
}
 
Example #8
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<List<Object>> slowlogGet() {
    return dispatch(commandBuilder.slowlogGet());
}
 
Example #9
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> addjob(K queue, V job, long commandTimeout, TimeUnit timeUnit, AddJobArgs addJobArgs) {
    return dispatch(commandBuilder.addjob(queue, job, commandTimeout, timeUnit, addJobArgs));
}
 
Example #10
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> clientList() {
    return dispatch(commandBuilder.clientList());
}
 
Example #11
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<List<String>> configGet(String parameter) {
    return dispatch(commandBuilder.configGet(parameter));
}
 
Example #12
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> clientSetname(String name) {
    return dispatch(commandBuilder.clientSetname(name));
}
 
Example #13
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<List<Object>> slowlogGet(int count) {
    return dispatch(commandBuilder.slowlogGet(count));
}
 
Example #14
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> clusterInfo() {
    return dispatch(commandBuilder.clusterInfo());
}
 
Example #15
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> debugFlushall() {
    return dispatch(commandBuilder.debugFlushall());
}
 
Example #16
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<KeyScanCursor<String>> jscan(ScanCursor scanCursor, JScanArgs<K> scanArgs) {
    return dispatch(commandBuilder.jscan(scanCursor, scanArgs));
}
 
Example #17
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<KeyScanCursor<K>> qscan(ScanCursor scanCursor, QScanArgs scanArgs) {
    return dispatch(commandBuilder.qscan(scanCursor, scanArgs));
}
 
Example #18
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<List<V>> time() {
    return dispatch(commandBuilder.time());
}
 
Example #19
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> clusterMyId() {
    return dispatch(commandBuilder.clusterMyId());
}
 
Example #20
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<Long> commandCount() {
    return dispatch(commandBuilder.commandCount());
}
 
Example #21
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<KeyScanCursor<String>> jscan() {
    return dispatch(commandBuilder.jscan(null, null));
}
 
Example #22
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> clusterSaveconfig() {
    return dispatch(commandBuilder.clusterSaveconfig());
}
 
Example #23
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> configResetstat() {
    return dispatch(commandBuilder.configResetstat());
}
 
Example #24
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> ping() {
    return dispatch(commandBuilder.ping());
}
 
Example #25
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<Long> enqueue(String... jobIds) {
    return dispatch(commandBuilder.enqueue(jobIds));
}
 
Example #26
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> slowlogReset() {
    return dispatch(commandBuilder.slowlogReset());
}
 
Example #27
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<List<Object>> show(String jobId) {
    return dispatch(commandBuilder.show(jobId));
}
 
Example #28
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<Long> dequeue(String... jobIds) {
    return dispatch(commandBuilder.dequeue(jobIds));
}
 
Example #29
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> clusterReset(boolean hard) {
    return dispatch(commandBuilder.clusterReset(hard));
}
 
Example #30
Source File: DisqueAsyncCommandsImpl.java    From spinach with Apache License 2.0 4 votes vote down vote up
@Override
public RedisFuture<String> clusterLeaving() {
    return dispatch(commandBuilder.clusterLeaving());
}