Search in sources :

Example 1 with Timeout

use of io.lettuce.core.dynamic.domain.Timeout in project lettuce-core by lettuce-io.

the class AsyncExecutableCommand method dispatchCommand.

protected Object dispatchCommand(Object[] arguments, RedisCommand<Object, Object, Object> command) throws InterruptedException, java.util.concurrent.ExecutionException {
    AsyncCommand<Object, Object, Object> asyncCommand = new AsyncCommand<>(command);
    if (commandMethod.isFutureExecution()) {
        RedisCommand<Object, Object, Object> dispatched = connection.dispatch(asyncCommand);
        if (dispatched instanceof AsyncCommand) {
            return dispatched;
        }
        return asyncCommand;
    }
    connection.dispatch(asyncCommand);
    Duration timeout = connection.getTimeout();
    if (commandMethod.getParameters() instanceof ExecutionSpecificParameters) {
        ExecutionSpecificParameters executionSpecificParameters = (ExecutionSpecificParameters) commandMethod.getParameters();
        if (executionSpecificParameters.hasTimeoutIndex()) {
            Timeout timeoutArg = (Timeout) arguments[executionSpecificParameters.getTimeoutIndex()];
            if (timeoutArg != null) {
                timeout = timeoutArg.getTimeout();
            }
        }
    }
    Futures.await(timeout, asyncCommand);
    return asyncCommand.get();
}
Also used : Timeout(io.lettuce.core.dynamic.domain.Timeout) AsyncCommand(io.lettuce.core.protocol.AsyncCommand) Duration(java.time.Duration) ExecutionSpecificParameters(io.lettuce.core.dynamic.parameter.ExecutionSpecificParameters)

Example 2 with Timeout

use of io.lettuce.core.dynamic.domain.Timeout in project lettuce-core by lettuce-io.

the class CommandSegmentCommandFactoryUnitTests method asyncWithTimeout.

@Test
void asyncWithTimeout() {
    try {
        createCommand(methodOf(MethodsWithTimeout.class, "async", String.class, Timeout.class), new StringCodec());
        fail("Missing CommandCreationException");
    } catch (CommandCreationException e) {
        assertThat(e).hasMessageContaining("Asynchronous command methods do not support Timeout parameters");
    }
}
Also used : StringCodec(io.lettuce.core.codec.StringCodec) Timeout(io.lettuce.core.dynamic.domain.Timeout) Test(org.junit.jupiter.api.Test)

Aggregations

Timeout (io.lettuce.core.dynamic.domain.Timeout)2 StringCodec (io.lettuce.core.codec.StringCodec)1 ExecutionSpecificParameters (io.lettuce.core.dynamic.parameter.ExecutionSpecificParameters)1 AsyncCommand (io.lettuce.core.protocol.AsyncCommand)1 Duration (java.time.Duration)1 Test (org.junit.jupiter.api.Test)1