avoid creating pipeline responses and do it lazy
This commit is contained in:
@@ -5,22 +5,29 @@ import redis.clients.jedis.exceptions.JedisDataException;
|
||||
public class Response<T> {
|
||||
protected T response = null;
|
||||
private boolean built = false;
|
||||
private boolean set = false;
|
||||
private Builder<T> builder;
|
||||
private Object data;
|
||||
|
||||
public Response(Builder<T> b) {
|
||||
this.builder = b;
|
||||
}
|
||||
|
||||
public void set(Object data) {
|
||||
response = builder.build(data);
|
||||
built = true;
|
||||
this.data = data;
|
||||
set = true;
|
||||
}
|
||||
|
||||
public T get() {
|
||||
if (!built) {
|
||||
if (!set) {
|
||||
throw new JedisDataException(
|
||||
"Please close pipeline or multi block before calling this method.");
|
||||
}
|
||||
if (!built) {
|
||||
response = builder.build(data);
|
||||
this.data = null;
|
||||
built = true;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user