2
2
3
3
import com .github .fppt .jedismock .datastructures .RMDataStructure ;
4
4
import com .github .fppt .jedismock .datastructures .RMHash ;
5
+ import com .github .fppt .jedismock .datastructures .RMString ;
5
6
import com .github .fppt .jedismock .datastructures .Slice ;
6
7
import com .github .fppt .jedismock .operations .server .MockExecutor ;
7
8
import com .github .fppt .jedismock .server .Response ;
11
12
12
13
import java .io .IOException ;
13
14
15
+ import static com .github .fppt .jedismock .Utils .convertToLong ;
16
+
14
17
public final class InterceptorMockServer {
15
18
16
19
public static final int PORT = 39807 ;
17
20
public static final Logger LOGGER = LoggerFactory .getLogger (InterceptorMockServer .class );
21
+ public static final int SHARED_OBJECT_THRESHOLD = 10000 ;
18
22
19
23
private InterceptorMockServer () {
20
24
@@ -39,11 +43,12 @@ public static void main(String[] args) throws IOException, InterruptedException
39
43
if (value instanceof RMHash ) {
40
44
RMHash hash = (RMHash ) value ;
41
45
return Response .bulkString (Slice .create (hash .getMeta ()));
46
+ } else if (value instanceof RMString ) {
47
+ return Response .bulkString (Slice .create (" at: " ));
42
48
}
43
49
return Response .bulkString (
44
50
Slice .create ("DEBUG OBJECT command for this data structure is not yet supported" )
45
51
);
46
-
47
52
} else if ("object" .equalsIgnoreCase (roName )
48
53
&& "encoding" .equalsIgnoreCase (params .get (0 ).toString ())
49
54
) {
@@ -59,7 +64,14 @@ public static void main(String[] args) throws IOException, InterruptedException
59
64
return Response .bulkString (
60
65
Slice .create ("OBJECT ENCODING command for this data structure is not yet supported" )
61
66
);
62
-
67
+ } else if ("object" .equalsIgnoreCase (roName )
68
+ && "refcount" .equalsIgnoreCase (params .get (0 ).toString ())
69
+ ) {
70
+ //Imitate shared objects
71
+ long val = convertToLong (state .base ().getRMString (params .get (1 )).getStoredDataAsString ());
72
+ if (val < SHARED_OBJECT_THRESHOLD ) return
73
+ Response .integer (2 );
74
+ else return Response .integer (1 );
63
75
} else {
64
76
//Delegate execution to JedisMock which will mock the real Redis behaviour (when it can)
65
77
return MockExecutor .proceed (state , roName , params );
0 commit comments