如何在Play 2.3.7中使用Redis

时间:2014-12-21 20:56:15

标签: scala playframework redis

我刚刚按the official guidelines启用了Redis。一切都编译好,并在应用程序首次启动时加载Redis

[info] application - Redis Plugin enabled. Connecting to Redis on localhost:6379 to 0 with timeout 2000.
[info] application - Redis Plugin pool configuration: redis.clients.jedis.JedisPoolConfig@287ab5fe[maxTotal=8,maxIdle=8,minIdle=0,lifo=true,maxWaitMillis=-1,minEvictableIdleTimeMillis=60000,softMinEvictableIdleTimeMillis=1800000,numTestsPerEvictionRun=-1,evictionPolicyClassName=org.apache.commons.pool2.impl.DefaultEvictionPolicy,testOnBorrow=false,testOnReturn=false,testWhileIdle=true,timeBetweenEvictionRunsMillis=30000,blockWhenExhausted=true,jmxEnabled=true,jmxNamePrefix=pool]

...但是一旦我尝试从我的应用程序中访问缓存,就像这样

Cache.set(id, tokenTrace, (expiration.getMillis / 1000).asInstanceOf[Int])

...我收到以下警告:

[warn] application - could not deserialize key:ecbba6d3-3ef2-4bbe-a979-d0e68ffee9bd ex:redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:42)
at org.sedis.Pool.withJedisClient(sedis.scala:101)
at com.typesafe.plugin.RedisPlugin$$anon$1.get(RedisPlugin.scala:178)
at play.api.cache.Cache$.get(Cache.scala:80)
at services.auth.cache.CacheTokenTraceDaoComponent$CacheTokenTraceDao$$anonfun$remove$2.apply$mcI$sp(CacheTokenTraceDaoComponent.scala:70)

我错过了什么吗?

修改

TokenTrace类只跟踪JWT,看起来像这样:

class TokenTrace private(protected var json: JsValue) extends JsEntity
  with Serializable {

  def id = json as (__ \ 'id).readNullable[String]
  def id_= (v: Option[String]) = setValue((__ \ 'id), Json.toJson(v))
  def username = json as (__ \ 'username).readNullable[String]
  def username_= (v: Option[String]) = setValue((__ \ 'username), Json.toJson(v))
  def expirationTime = json as (__ \ 'expirationTime).read[DateTime]
  def expirationTime_= (v: DateTime) = setValue((__ \ 'expirationTime), Json.toJson(v))

  def copy(json: JsValue) = throw new UnsupportedOperationException
  override def toString = json.toString
} 

0 个答案:

没有答案