Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Advanced and thread-safe Java Redis client for synchronous, asynchronous, and
reactive usage. Supports Cluster, Sentinel, Pipelining, Auto-Reconnect, Codecs
and much more.
/*
* Copyright 2011-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lambdaworks.redis.dynamic;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import com.lambdaworks.redis.AbstractRedisReactiveCommands;
import com.lambdaworks.redis.LettuceFutures;
import com.lambdaworks.redis.RedisFuture;
import com.lambdaworks.redis.api.StatefulConnection;
import com.lambdaworks.redis.api.StatefulRedisConnection;
import com.lambdaworks.redis.api.async.BaseRedisAsyncCommands;
import com.lambdaworks.redis.api.reactive.BaseRedisReactiveCommands;
import com.lambdaworks.redis.cluster.api.StatefulRedisClusterConnection;
import com.lambdaworks.redis.codec.ByteArrayCodec;
import com.lambdaworks.redis.codec.RedisCodec;
import com.lambdaworks.redis.codec.StringCodec;
import com.lambdaworks.redis.dynamic.codec.AnnotationRedisCodecResolver;
import com.lambdaworks.redis.dynamic.domain.Timeout;
import com.lambdaworks.redis.dynamic.intercept.InvocationProxyFactory;
import com.lambdaworks.redis.dynamic.intercept.MethodInterceptor;
import com.lambdaworks.redis.dynamic.intercept.MethodInvocation;
import com.lambdaworks.redis.dynamic.output.CodecAwareOutputFactoryResolver;
import com.lambdaworks.redis.dynamic.output.CommandOutputFactoryResolver;
import com.lambdaworks.redis.dynamic.output.OutputRegistry;
import com.lambdaworks.redis.dynamic.output.OutputRegistryCommandOutputFactoryResolver;
import com.lambdaworks.redis.dynamic.parameter.ExecutionSpecificParameters;
import com.lambdaworks.redis.dynamic.segment.AnnotationCommandSegmentFactory;
import com.lambdaworks.redis.dynamic.segment.CommandSegments;
import com.lambdaworks.redis.internal.LettuceAssert;
import com.lambdaworks.redis.internal.LettuceLists;
import com.lambdaworks.redis.models.command.CommandDetail;
import com.lambdaworks.redis.models.command.CommandDetailParser;
import com.lambdaworks.redis.output.CommandOutput;
import com.lambdaworks.redis.protocol.CommandArgs;
import com.lambdaworks.redis.protocol.LettuceCharsets;
import com.lambdaworks.redis.protocol.RedisCommand;
/**
* Factory to create Redis Command interface instances.
*
* This class is the entry point to implement command interfaces and obtain a reference to the implementation. Redis Command
* interfaces provide a dynamic API that are declared in userland code. {@link RedisCommandFactory} and its supportive classes
* analyze method declarations and derive from those factories to create and execute {@link RedisCommand}s.
*
*
Example
public interface MyRedisCommands {
String get(String key); // Synchronous Execution of GET
@Command("GET")
byte[] getAsBytes(String key); // Synchronous Execution of GET returning data as byte array
@Command("SET") // synchronous execution applying a Timeout
String setSync(String key, String value, Timeout timeout);
Future set(String key, String value); // asynchronous SET execution
@Command("SET")
Mono setReactive(String key, String value, SetArgs setArgs); // reactive SET execution using SetArgs
@CommandNaming(split = DOT) // support for Redis Module command notation -> NR.RUN
double nrRun(String key, int... indexes);
}
RedisCommandFactory factory = new RedisCommandFactory(connection);
MyRedisCommands commands = factory.getCommands(MyRedisCommands.class);
String value = commands.get("key");
*
*
* @author Mark Paluch
* @since 5.0
* @see com.lambdaworks.redis.dynamic.annotation.Command
* @see CommandMethod
*/
public class RedisCommandFactory {
private final StatefulConnection, ?> connection;
private final CommandMethodVerifier commandMethodVerifier;
private final List> redisCodecs = new ArrayList<>();
private CommandOutputFactoryResolver commandOutputFactoryResolver = new OutputRegistryCommandOutputFactoryResolver(
new OutputRegistry());
private boolean verifyCommandMethods = true;
/**
* Create a new {@link CommandFactory} given {@link StatefulConnection}.
*
* @param connection must not be {@literal null}.
*/
public RedisCommandFactory(StatefulConnection, ?> connection) {
this(connection, LettuceLists.newList(new ByteArrayCodec(), new StringCodec(LettuceCharsets.UTF8)));
}
/**
* Create a new {@link CommandFactory} given {@link StatefulConnection} and a {@link List} of {@link RedisCodec}s to use
*
* @param connection must not be {@literal null}.
* @param redisCodecs must not be {@literal null}.
*/
public RedisCommandFactory(StatefulConnection, ?> connection, Iterable> redisCodecs) {
LettuceAssert.notNull(connection, "Redis Connection must not be null");
LettuceAssert.notNull(redisCodecs, "Iterable of RedisCodec must not be null");
this.connection = connection;
this.redisCodecs.addAll(LettuceLists.newList(redisCodecs));
commandMethodVerifier = new CommandMethodVerifier(getCommands(connection));
}
@SuppressWarnings("unchecked")
private List getCommands(StatefulConnection, ?> connection) {
List