【发布时间】:2016-02-18 18:33:00
【问题描述】:
我将 Redis 用作播放应用程序中的捕获。使用 Redis,我可以存储一些与 case class Cache1 中的键字符串相关联的字符串列表:
case class Cache1(val hostname : String, val port : Int, val timeout : Int) {
val pool : Pool =
new Pool(new JedisPool(new JedisPoolConfig(), hostname, port, timeout))
val j = pool.underlying.getResource
j.flushAll
pool.underlying.returnResourceObject(j)
def set(key : String, value : String) : Unit = pool.withClient { client =>
client.lpush(key, value)
}
def get(key : String) : Option[List[String]] = {
pool.withClient { client =>
val l : List[String] =
Dress.up(client).lrange(key, 0, Dress.up(client).llen(key)-1)
if(l.length == 0) return None else return Some(l)
}
}
}
我想重现相同的案例类,但将String 存储为值,我想存储ListBuffer[List[Double]]。但是我在 redis API 中找不到这样做的方法,这就是我在这里问这个问题的原因。
【问题讨论】:
-
重要的是您想如何使用这些数据?你想只获取一条记录(ListBuffer[2][3])还是想获取整个列表缓冲区(ListBuffer[2])?
-
我需要得到整个
ListBuffer,而不仅仅是他的几分。 -
只是为了保证,您总是需要整个列表缓冲区?
-
是的,总是。我想将几个键与此类数据相关联。喜欢
1 -> ListBuffer(List(1,2), List(3,4)), 2 -> ListBuffer(List(10,10), List(20,20))。