Commit 5250cae6 authored by 赵威's avatar 赵威

write json

parent 41bdc245
......@@ -4,6 +4,10 @@ import scala.concurrent.Future
import scala.collection.JavaConverters._
import com.alibaba.fastjson.JSON
import com.redis.{ RedisClient, RedisClientPool }
import org.json4s._
import org.json4s.jackson.Serialization
import org.json4s.jackson.Serialization.{ read, write }
import org.json4s.jackson.JsonMethods._
object Redis {
// TODO read from config file
......@@ -65,6 +69,8 @@ object Redis {
contentEitherFuture: Either[Throwable, Future[IndexedSeq[Content]]],
deviceId: String
): Unit = {
implicit val formats = Serialization.formats(NoTypeHints)
val key = s"streaming:candidate:service_diary:device_id:${deviceId}"
contentEitherFuture match {
case Left(e) => e.printStackTrace()
......@@ -72,12 +78,11 @@ object Redis {
pRc4.withClient { client =>
contentFuture.foreach { seq =>
val idPairs = seq.map(c => (c.id, c.serviceId.getOrElse("-1")))
println(idPairs)
val a = write(idPairs)
println(a)
if (idPairs.size > 0) {
client.del(key)
idPairs.foreach { pair =>
client.rpush(key, pair)
}
client.set(key, a)
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment