在代碼裏對一個值爲long類型key執行incrby操做,一直都正常,突發一例異常:
html
Caused by: java.lang.ClassCastException: [B cannot be cast to java.lang.Long at redis.clients.jedis.Connection.getIntegerReply(Connection.java:210) at redis.clients.jedis.Jedis.incrBy(Jedis.java:556) at com.xxx.xxxxxClient.incrBy(SingleJedisClientImpl.java:119) ... 19 common frames omitted
其中com.xxx.xxxxxClient.incrBy是jedis客戶端的一個封裝和管理。應該是xxxxxClient這裏出了問題。再或者是jedis自己線程池管理出了問題。java
----------------如下是網上資料,轉自http://mengkang.net/443.html---------------------------------------redis
Caused by: java.lang.ClassCastException: [B cannot be cast to java.util.List at redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:218) at redis.clients.jedis.Connection.getMultiBulkReply(Connection.java:211) at redis.clients.jedis.Jedis.lrange(Jedis.java:862) at me.topit.site.util.redis.CacheClientBase.lrange(CacheClientBase.java:516) at me.topit.site.cache.TagCache.get(TagCache.java:37) at me.topit.site.model.Tags.getUserSelectedTags(Tags.java:141) at me.topit.site.service.FeedService.getType(FeedService.java:41) 或者 Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to [B at redis.clients.jedis.Connection.getBinaryBulkReply(Connection.java:201) at redis.clients.jedis.Connection.getBulkReply(Connection.java:190) at redis.clients.jedis.Jedis.hget(Jedis.java:601) at me.topit.site.util.redis.CacheClientBase.hget(CacheClientBase.java:51) at me.topit.site.cache.AccountCache.getAuth(AccountCache.java:30) at me.topit.site.model.Account.getAuth(Account.java:137) at me.topit.site.service.AccountService.loginCheck(AccountService.java:112) at me.topit.site.service.BaseService.isLogin(BaseService.java:87) at me.topit.site.service.PushService.bind(PushService.java:53)
後來發現是由於我作了redis 鏈接的線程池,使用的一直是一個在父類裏申明的靜態變量,各個地方調,都是直接用.使用完以後也沒有釋放.因此每次項目跑着跑着,過幾個小時就訪問超級慢.最後發現是由於使用的是一個鏈接的緣由. 如今改成每次使用都先初始化,而後每次用完以後都釋放. .net
------------------------------------------------------------------------------------------------------------線程
多是做者提到的這個緣由。未確認。code