1717import redis .clients .jedis .commands .SampleBinaryKeyedCommands ;
1818import redis .clients .jedis .commands .SampleKeyedCommands ;
1919import redis .clients .jedis .commands .RedisModuleCommands ;
20+ import redis .clients .jedis .exceptions .JedisException ;
2021import redis .clients .jedis .executors .*;
2122import redis .clients .jedis .graph .GraphCommandObjects ;
2223import redis .clients .jedis .graph .ResultSet ;
@@ -41,9 +42,10 @@ public class UnifiedJedis implements JedisCommands, JedisBinaryCommands,
4142 SampleKeyedCommands , SampleBinaryKeyedCommands , RedisModuleCommands ,
4243 AutoCloseable {
4344
45+ protected RedisProtocol protocol = null ;
4446 protected final ConnectionProvider provider ;
4547 protected final CommandExecutor executor ;
46- private final CommandObjects commandObjects ;
48+ protected final CommandObjects commandObjects ;
4749 private final GraphCommandObjects graphCommandObjects ;
4850 private JedisBroadcastAndRoundRobinConfig broadcastAndRoundRobinConfig = null ;
4951
@@ -91,6 +93,15 @@ public UnifiedJedis(ConnectionProvider provider) {
9193 this .commandObjects = new CommandObjects ();
9294 this .graphCommandObjects = new GraphCommandObjects (this );
9395 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+ }
94105 }
95106
96107 /**
@@ -103,6 +114,16 @@ public UnifiedJedis(JedisSocketFactory socketFactory) {
103114 this (new Connection (socketFactory ));
104115 }
105116
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+
106127 /**
107128 * The constructor to directly use a {@link Connection}.
108129 * <p>
@@ -114,6 +135,8 @@ public UnifiedJedis(Connection connection) {
114135 this .executor = new SimpleCommandExecutor (connection );
115136 this .commandObjects = new CommandObjects ();
116137 this .graphCommandObjects = new GraphCommandObjects (this );
138+ RedisProtocol proto = connection .getRedisProtocol ();
139+ if (proto == RedisProtocol .RESP3 ) this .commandObjects .setProtocol (proto );
117140 }
118141
119142 public UnifiedJedis (Set <HostAndPort > jedisClusterNodes , JedisClientConfig clientConfig , int maxAttempts ) {
@@ -195,6 +218,11 @@ public void close() {
195218 IOUtils .closeQuietly (this .executor );
196219 }
197220
221+ protected final void setProtocol (RedisProtocol protocol ) {
222+ this .protocol = protocol ;
223+ this .commandObjects .setProtocol (this .protocol );
224+ }
225+
198226 public final <T > T executeCommand (CommandObject <T > commandObject ) {
199227 return executor .executeCommand (commandObject );
200228 }
@@ -4685,7 +4713,7 @@ public List<String> graphExplain(String graphName, String query) {
46854713 }
46864714
46874715 @ Override
4688- public List <List <String >> graphSlowlog (String graphName ) {
4716+ public List <List <Object >> graphSlowlog (String graphName ) {
46894717 return executeCommand (commandObjects .graphSlowlog (graphName ));
46904718 }
46914719
0 commit comments