forked from pyb1993/JavaRedis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedisObject.java
More file actions
75 lines (58 loc) · 1.66 KB
/
RedisObject.java
File metadata and controls
75 lines (58 loc) · 1.66 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package RedisDataBase;
import Common.RedisUtil;
import java.util.HashMap;
/** 用来实现一个RedisObject 里面可封装各种数据结构
* 1 Integer(String)
* 2 List
* 3 Hash
* 4 Set
* 5 Zset
*
* **/
public class RedisObject {
static int REDIS_INTEGER = 1;
static int REDIS_STRING = 2;
static int REDIS_LIST = 3;
static int REDIS_HASH = 4;
static int REDIS_SET = 5;
static int REDIS_ZSET = 6;
static int REDIS_HYPERLOGLOG = 7;
private int type;
private Object data;
// 返回一个RedisObject,参数是String,可能是Integer,或者是普通String
static public RedisObject redisStringObject(RedisString obj){
return new RedisObject(REDIS_STRING,obj);
}
// 返回一个RedisObject,参数是HashMap
static public RedisObject redisHashObject(RedisDict<RedisString,RedisObject> obj){
return new RedisObject(REDIS_HASH,obj);
}
public RedisObject(int type,Object data){
this.type = type;
this.data = data;
}
public Object getData(){
return data;
}
public boolean isInteger(){
return type == REDIS_INTEGER;
}
public boolean isString(){
return type == REDIS_STRING;
}
@Override
public int hashCode() {
return (data.hashCode() | (type << 10)) ^ 0x14D54B57;
}
// if other is null, return false
// if type != other.type || !data.equals(other.data), return
public boolean equals(RedisObject other){
if( !super.equals(other)){
return false;
}
if(type != other.type || !data.equals(other.data)){
return false;
}
return true;
}
}