我正在使用Redis作为播放应用程序中的catching。使用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)
}
}
}我希望重现相同的case类,但我希望存储一个ListBuffer[List[Double]],而不是将String存储为值。但是我在redis API中找不到这样做的方法,这就是为什么我在这里问这个问题。
发布于 2015-11-17 23:26:23
我将整个结构存储为JSON,并将其读取为JSON。这很简单,也很容易维护。
Redis商店列表
object MyJacksonMapper extends JacksonMapper
val jsonListBuffer= MyJacksonMapper.serializeJson(myListBuffer)
Dress.up(client).set("listbuffer",jsonListBuffer)Redis Get
val json = Dress.up(client).get("listbuffer")
val myNewObject = MyJacksonMapper.deserializeJson[ListBuffer](json)https://stackoverflow.com/questions/33756073
复制相似问题