17
17
import redis .clients .jedis .commands .SampleBinaryKeyedCommands ;
18
18
import redis .clients .jedis .commands .SampleKeyedCommands ;
19
19
import redis .clients .jedis .commands .RedisModuleCommands ;
20
+ import redis .clients .jedis .exceptions .JedisException ;
20
21
import redis .clients .jedis .executors .*;
21
22
import redis .clients .jedis .graph .GraphCommandObjects ;
22
23
import redis .clients .jedis .graph .ResultSet ;
@@ -41,9 +42,10 @@ public class UnifiedJedis implements JedisCommands, JedisBinaryCommands,
41
42
SampleKeyedCommands , SampleBinaryKeyedCommands , RedisModuleCommands ,
42
43
AutoCloseable {
43
44
45
+ protected RedisProtocol protocol = null ;
44
46
protected final ConnectionProvider provider ;
45
47
protected final CommandExecutor executor ;
46
- private final CommandObjects commandObjects ;
48
+ protected final CommandObjects commandObjects ;
47
49
private final GraphCommandObjects graphCommandObjects ;
48
50
private JedisBroadcastAndRoundRobinConfig broadcastAndRoundRobinConfig = null ;
49
51
@@ -91,6 +93,15 @@ public UnifiedJedis(ConnectionProvider provider) {
91
93
this .commandObjects = new CommandObjects ();
92
94
this .graphCommandObjects = new GraphCommandObjects (this );
93
95
this .graphCommandObjects .setBaseCommandArgumentsCreator ((comm ) -> this .commandObjects .commandArguments (comm ));
96
+ try (Connection conn = this .provider .getConnection ()) {
97
+ if (conn != null ) {
98
+ RedisProtocol proto = conn .getRedisProtocol ();
99
+ if (proto != null ) commandObjects .setProtocol (proto );
100
+ }
101
+ //} catch (JedisAccessControlException ace) {
102
+ } catch (JedisException je ) { // TODO: use specific exception(s)
103
+ // use default protocol
104
+ }
94
105
}
95
106
96
107
/**
@@ -103,6 +114,16 @@ public UnifiedJedis(JedisSocketFactory socketFactory) {
103
114
this (new Connection (socketFactory ));
104
115
}
105
116
117
+ /**
118
+ * The constructor to directly use a custom {@link JedisSocketFactory}.
119
+ * <p>
120
+ * WARNING: Using this constructor means a {@link NullPointerException} will be occurred if
121
+ * {@link UnifiedJedis#provider} is accessed.
122
+ */
123
+ public UnifiedJedis (JedisSocketFactory socketFactory , JedisClientConfig clientConfig ) {
124
+ this (new Connection (socketFactory , clientConfig ));
125
+ }
126
+
106
127
/**
107
128
* The constructor to directly use a {@link Connection}.
108
129
* <p>
@@ -114,6 +135,8 @@ public UnifiedJedis(Connection connection) {
114
135
this .executor = new SimpleCommandExecutor (connection );
115
136
this .commandObjects = new CommandObjects ();
116
137
this .graphCommandObjects = new GraphCommandObjects (this );
138
+ RedisProtocol proto = connection .getRedisProtocol ();
139
+ if (proto == RedisProtocol .RESP3 ) this .commandObjects .setProtocol (proto );
117
140
}
118
141
119
142
public UnifiedJedis (Set <HostAndPort > jedisClusterNodes , JedisClientConfig clientConfig , int maxAttempts ) {
@@ -195,6 +218,11 @@ public void close() {
195
218
IOUtils .closeQuietly (this .executor );
196
219
}
197
220
221
+ protected final void setProtocol (RedisProtocol protocol ) {
222
+ this .protocol = protocol ;
223
+ this .commandObjects .setProtocol (this .protocol );
224
+ }
225
+
198
226
public final <T > T executeCommand (CommandObject <T > commandObject ) {
199
227
return executor .executeCommand (commandObject );
200
228
}
@@ -4685,7 +4713,7 @@ public List<String> graphExplain(String graphName, String query) {
4685
4713
}
4686
4714
4687
4715
@ Override
4688
- public List <List <String >> graphSlowlog (String graphName ) {
4716
+ public List <List <Object >> graphSlowlog (String graphName ) {
4689
4717
return executeCommand (commandObjects .graphSlowlog (graphName ));
4690
4718
}
4691
4719
0 commit comments