一、問題分析
事情經過是這樣,我們使用了阿里雲的redis 集羣版,今天上班同事告訴我,redis不能正常使用了,控制檯有大量以下錯誤:
NOREAD You can't read against a non-read redis.
詳細異常堆棧如下:
org.springframework.dao.InvalidDataAccessApiUsageException: NOREAD You can't read against a non-read redis.; nested exception is redis.clients.jedis.exceptions.JedisDataException: NOREAD You can't read against a non-read redis.
at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:44)
at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:36)
at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:37)
at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:37)
at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:210)
at org.springframework.data.redis.connection.jedis.JedisConnection.sMembers(JedisConnection.java:1900)
at org.springframework.data.redis.core.DefaultSetOperations$7.doInRedis(DefaultSetOperations.java:130)
於是乎根據上面堆棧先排查連接配置信息是否正確,然後又分析了半天源碼!最後機智如我,直接登錄上去看redis的狀態,然後來個超級簡單的檢測命令:set i i
於是報了下面錯誤:
NOWRITE You can't write against a non-write redis.
這個時候已經很明顯了,明顯是該redis 集羣出問題了,和程序、連接配置都無關。
果斷打開阿里雲redis控制檯,發現redis到期了,被禁止使用了。
續費之後,問題解決。
二、總結
set ${key} ${value} 報“NOWRITE You can't write against a non-write redis.”錯誤,那報“NOREAD You can't read against a non-read redis.”錯誤,就應該是get ${key} 導致的。
三、擴展
文末附上阿里雲集羣常見其他錯誤
NOWRITE You can't write against a non-write redis
DB處於只讀狀態,主要發生在變配、小版本升級等流程中。
DISABLE You can't write or read against a disable instance
目前處於鎖定狀態,一般是用戶欠費。
redis tempory failure or response big than 500MB
redis請求的value最大不能超過500MB,超過之後返回該錯誤信息。
node idx is invalid
node num specified >= node count
主要出現在iinfo, riinfo, iscan, imonitor等命令中,用於指定節點的index不在合法範圍內。
command keys must in same slot
集羣實例中,事務、腳本等命令要求所有key必須在同一個slot中,如果不在同一個slot中返回該錯誤。
for redis cluster, eval/evalsha number of keys can't be negative or zero
eval和evalsha命令必須至少帶一個key,numkeys參數大於0。
request refused, too many pending request
後端堆積了過多未處理完的request,新請求被拒絕。出現的原因是因爲客戶端使不合理的使用了pipeline。