63
63
* @author Thomas Darimont
64
64
* @author Christoph Strobl
65
65
* @author Mark Paluch
66
+ * @author Fu Jian
66
67
*/
67
68
public class JedisConnectionFactory implements InitializingBean , DisposableBean , RedisConnectionFactory {
68
69
@@ -101,6 +102,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
101
102
private Pool <Jedis > pool ;
102
103
private JedisPoolConfig poolConfig = new JedisPoolConfig ();
103
104
private int dbIndex = 0 ;
105
+ private String clientName ;
104
106
private boolean convertPipelineAndTxResults = true ;
105
107
private RedisSentinelConfiguration sentinelConfig ;
106
108
private RedisClusterConfiguration clusterConfig ;
@@ -255,7 +257,7 @@ private Pool<Jedis> createPool() {
255
257
protected Pool <Jedis > createRedisSentinelPool (RedisSentinelConfiguration config ) {
256
258
return new JedisSentinelPool (config .getMaster ().getName (), convertToJedisSentinelSet (config .getSentinels ()),
257
259
getPoolConfig () != null ? getPoolConfig () : new JedisPoolConfig (), getTimeoutFrom (getShardInfo ()),
258
- getShardInfo ().getPassword ());
260
+ getShardInfo ().getPassword (), Protocol . DEFAULT_DATABASE , clientName );
259
261
}
260
262
261
263
/**
@@ -267,7 +269,7 @@ protected Pool<Jedis> createRedisSentinelPool(RedisSentinelConfiguration config)
267
269
protected Pool <Jedis > createRedisPool () {
268
270
269
271
return new JedisPool (getPoolConfig (), getShardInfo ().getHost (), getShardInfo ().getPort (),
270
- getTimeoutFrom (getShardInfo ()), getShardInfo ().getPassword (), useSsl );
272
+ getTimeoutFrom (getShardInfo ()), getShardInfo ().getPassword (), Protocol . DEFAULT_DATABASE , clientName , useSsl );
271
273
}
272
274
273
275
private JedisCluster createCluster () {
@@ -530,6 +532,24 @@ public void setDatabase(int index) {
530
532
Assert .isTrue (index >= 0 , "invalid DB index (a positive index required)" );
531
533
this .dbIndex = index ;
532
534
}
535
+
536
+ /**
537
+ * Returns the client name.
538
+ *
539
+ * @return Returns the client name
540
+ */
541
+ public String getClientName () {
542
+ return clientName ;
543
+ }
544
+
545
+ /**
546
+ * Sets the client name used by this connection factory. Default is empty.
547
+ *
548
+ * @param clientName client name
549
+ */
550
+ public void setClientName (String clientName ) {
551
+ this .clientName = clientName ;
552
+ }
533
553
534
554
/**
535
555
* Specifies if pipelined results should be converted to the expected data type. If false, results of
0 commit comments