zj
2025-04-04 8ceb6cd5ba9d7f347f2070a3967f31cc070ef4ef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package project.redis.clients.jedis;
 
import redis.clients.jedis.Builder;
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) {
        this.data = data;
        set = true;
    }
 
    public T get() {
        if (!set) {
            throw new JedisDataException(
                    "Please close pipeline or multi block before calling this method.");
        }
        if (!built) {
            //  数据为空是直接返回null,避免 builder.build(data)产生空指针异常
            if(data == null) {
                return null;
            }
            response = builder.build(data);
            this.data = null;
            built = true;
        }
        return response;
    }
 
    public String toString() {
        return "Response " + builder.toString();
    }
 
}