Posted 绌嗘枃鏂岀殑鍏紬骞冲彴
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了相关的知识,希望对你有一定的参考价值。
鑳屾櫙
鑰侀」鐩敼閫犱腑锛宺edis杩佺Щ锛堣繕鏄€侀」鐩敼閫狆煒濓級銆?/span>
鏃ч泦缇よ繛鎺ヤ笉闇€瑕佸瘑鐮侊紝鑰屾柊闆嗙兢闇€瑕併€傝縼绉绘秹鍙婂埌23涓」鐩€?/span>
鍏朵腑涓€涓」鐩敼閫犱笂绾垮悗鍑虹幇璁よ瘉澶辫触鐨勯棶棰橈紙寮傚父鏃ュ織锛夛細
[2021-03-30 11:46:29.249 tjtx144-127-214.58os.org happyhours-service] [ERROR] [http-nio-8018-exec-8] (RedisSessionManager:63) [TxId: SpanId:] 鑾峰彇session鏃跺嚭鐜扮紦瀛樺紓甯?寮傚父淇℃伅redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.
at redis.clients.jedis.Protocol.processError(Protocol.java:127)
...
Redis杩炴帴绫讳腑涓昏浠g爜鐗囨锛堜唬鐮佹锛夛細
public JedisPool func1(JedisPoolConfig jedisPoolConfig) {
JedisPool jedisPool = new JedisPool(jedisPoolConfig,host,port);
return jedisPool;
}
public JedisConnectionFactory func2(
JedisPoolConfig jedisPoolConfig) {
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setHostName(host);
factory.setPort(port);
factory.setPassword(password);//鏀归€犳柊澧?/span>
factory.setPoolConfig(jedisPoolConfig);
return factory;
}
杩佺Щ鏀归€犳椂锛屽彧淇敼浜?code class="mq-12">func2()鍑芥暟锛屽鍔犱簡绗?0琛屻€傝礋璐f敼閫犵殑鍚屽搴旇鏄病鏈夋敞鎰忓埌func1()
涓篃鏈夎繛鎺ョ殑鍒濆鍖栬缃€?/span>
涓や釜鍑芥暟瀹炵幇鐨勫姛鑳戒娇鐢ㄤ竴鏍风殑锛屾洿宸х殑鏄敼閫犵殑椤圭洰涓繛鎺edis鎿嶄綔骞舵病鏈変娇鐢?code class="mq-18">func2()...锛屾敼閫犵殑鍚屽娌挎儻鎬ф€濈淮锛堝凡鏀归€犵殑椤圭洰涓兘鐢ㄧ被浼?code class="mq-20">func2()鍑芥暟锛夊彧淇敼浜嗕竴澶勷煒€?/span>
鎵€浠ョ洿鎺ョ殑淇敼鏂瑰紡鏄紝绗?琛屾敼涓猴細
JedisPool jedisPool =
new JedisPool(jedisPoolConfig,host,port,20000,password);
瀹炵幇瀵规瘮
杩欎釜闂骞朵笉澶嶆潅锛屽€熻繖涓簨鎯冲姣斾竴涓?code class="mq-29">JedisPool鍜?code class="mq-31">JedisConnectionFactory鍔熻兘涓婄殑寮傚悓锛屼互鍙婂湪Pool瀹炵幇涓婃垜瑙夊緱鍊煎緱鍊熼壌鐨勫疄鐜版柟寮忋€?/span>
JedisPool
瀹炵幇浜嗕竴涓繛鎺ユ睜Pool銆?/span>
鑰?code class="mq-42">JedisConnectionFactory瀹炵幇浜?em class="mq-44">Cluster銆?em class="mq-47">Sentinel鍜?em class="mq-50">Pool涓夌杩炴帴鏂瑰紡銆?em class="mq-53">Pool鐨勫疄鐜板氨鏄垱寤轰竴涓?code class="mq-56">JedisPool銆?/span>
//JedisConnectionFactory.java 鍒涘缓Pool鐨勪唬鐮佹
protected Pool<Jedis> createRedisPool() {
return new JedisPool(getPoolConfig(), getShardInfo().getHost(),
getShardInfo().getPort(),getTimeoutFrom(getShardInfo()),
getShardInfo().getPassword(),
Protocol.DEFAULT_DATABASE, clientName, useSsl);
}
鍙JedisPool
鍦ㄥ姛鑳戒笂鍙槸JedisConnectionFactory
鐨勪竴涓瓙闆嗐€?/span>
濡傛灉鍙槸鍗曡妭鐐圭殑Redis鍙敤杞婚噺JedisPool
鍘诲疄鐜拌繛鎺ョ鐞嗐€傚湪闆嗙兢鍦烘櫙涓嬶紝鏇存帹鑽愪娇鐢?code class="mq-68">JedisConnectionFactory銆?/span>
娣卞叆Pool瀹炵幇
鍐嶆繁鍏ョ湅涓€涓嬭繛鎺ユ睜Pool鐨勫疄鐜般€?/span>
浠庢簮鐮佷笂鐪?code class="mq-79">JedisPool鏀寔浜唖slsocket锛堝畨鍏ㄥ鎺ュ瓧锛夊拰socket锛堟櫘閫氬鎺ュ瓧锛夊崗璁€?/span>
public JedisPool(final String host) {
...
}
public JedisPool(final String host,
final SSLSocketFactory sslSocketFactory,
final SSLParameters sslParameters,
final HostnameVerifier hostnameVerifier) {
...
}
涓€涓湁瓒g殑鍙戠幇鏄?code class="mq-83">JedisPool涓娇鐢?code class="mq-85">GenericObjectPool瀹炰綋锛堝湪鐖剁被Pool.java
鐨勫睘鎬т腑瀹氫箟internalPool
锛夊畾涔夋睜銆?/span>
椤虹潃杩欐潯绾垮線涓嬬湅锛屽彂鐜?code class="mq-93">GenericObjectPool鏄痑pache瀹炵幇鐨勪竴涓€氱敤鐨勬睜瀵硅薄锛屾敮鎸佹硾鍨嬨€?/span>
杩欓噷浣跨敤LinkedBlockingDeque
瀹屾垚鍏蜂綋姹犲璞$殑绠$悊銆?/span>
绫?code class="mq-101">GenericObjectPool.java鐨刄ML鍏崇郴鍥惧涓嬶細
GenericObjectPool.java
鎻愪緵鎿嶄綔Pool鐨勫畬鍠勭殑鏂规硶闆?/span>
璁剧疆Pool灞炴€х殑setMaxIdle()
銆?code class="mq-121">setMinIdle()浠ュ強鐖剁被BaseGenericObjectPool
涓殑灞炴€ц缃嚱鏁般€?code class="mq-125">borrowObject()銆?code class="mq-127">getFactory()绛夊Pool鎿嶄綔鍑芥暟銆?/span>
鎵€鏈夛紝褰撴垜浠渶瑕佽嚜宸卞疄鐜颁竴涓?em class="mq-136">Pool鏃讹紝鍙互鍊熼壌JedisPool
鐨勫疄鐜版柟寮忥細闆嗘垚GenericObjectPool
绫伙紝鑰屼笉鏄嚜宸卞幓瀹炵幇鏁村Pool鐨勭鐞嗐€?/span>
渚濊禆鐗堟湰
SpringBoot鐨勭増鏈槸锛堟槸鍟婏紝鐗堟湰寰堟棫馃槀锛夛細
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starters</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
Jedis渚濊禆锛?/span>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
以上是关于的主要内容,如果未能解决你的问题,请参考以下文章