File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
main/java/dev/keva/core/command/mapping
test/java/dev/keva/core/server Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1919import lombok .Getter ;
2020import lombok .extern .slf4j .Slf4j ;
2121import lombok .val ;
22+ import org .apache .commons .lang3 .SerializationException ;
2223import org .reflections .Reflections ;
2324
2425import java .lang .reflect .InvocationTargetException ;
@@ -120,7 +121,7 @@ public void init() {
120121 } catch (Exception e ) {
121122 log .error (e .getMessage (), e );
122123 if (e instanceof InvocationTargetException ) {
123- if (e .getCause () instanceof ClassCastException ) {
124+ if (e .getCause () instanceof SerializationException || e . getCause () instanceof ClassCastException ) {
124125 return new ErrorReply ("ERR WRONGTYPE Operation against a key holding the wrong kind of value" );
125126 }
126127 return new ErrorReply ("ERR " + e .getCause ().getMessage ());
Original file line number Diff line number Diff line change @@ -106,6 +106,39 @@ void del() {
106106 }
107107 }
108108
109+ @ Test
110+ void wrongTypeSet () {
111+ try {
112+ val setAbc = jedis .set ("abc" , "123" );
113+ assertEquals ("OK" , setAbc );
114+ jedis .lpush ("abc" , "123" );
115+ } catch (Exception e ) {
116+ assertEquals (JedisDataException .class , e .getClass ());
117+ }
118+ }
119+
120+ @ Test
121+ void wrongTypeSet2 () {
122+ try {
123+ val setAbc = jedis .lpush ("abc" , "123" );
124+ assertEquals (1 , setAbc );
125+ jedis .hset ("abc" , "key" , "val" );
126+ } catch (Exception e ) {
127+ assertEquals (JedisDataException .class , e .getClass ());
128+ }
129+ }
130+
131+ @ Test
132+ void wrongTypeSet3 () {
133+ try {
134+ val setAbc = jedis .hset ("abc" , "key" , "val" );
135+ assertEquals (1 , setAbc );
136+ jedis .lpush ("abc" , "123" );
137+ } catch (Exception e ) {
138+ assertEquals (JedisDataException .class , e .getClass ());
139+ }
140+ }
141+
109142 @ Test
110143 void transaction () {
111144 try {
You can’t perform that action at this time.
0 commit comments