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

write json

parent 41bdc245
...@@ -4,6 +4,10 @@ import scala.concurrent.Future ...@@ -4,6 +4,10 @@ import scala.concurrent.Future
import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
import com.alibaba.fastjson.JSON import com.alibaba.fastjson.JSON
import com.redis.{ RedisClient, RedisClientPool } 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 { object Redis {
// TODO read from config file // TODO read from config file
...@@ -65,6 +69,8 @@ object Redis { ...@@ -65,6 +69,8 @@ object Redis {
contentEitherFuture: Either[Throwable, Future[IndexedSeq[Content]]], contentEitherFuture: Either[Throwable, Future[IndexedSeq[Content]]],
deviceId: String deviceId: String
): Unit = { ): Unit = {
implicit val formats = Serialization.formats(NoTypeHints)
val key = s"streaming:candidate:service_diary:device_id:${deviceId}" val key = s"streaming:candidate:service_diary:device_id:${deviceId}"
contentEitherFuture match { contentEitherFuture match {
case Left(e) => e.printStackTrace() case Left(e) => e.printStackTrace()
...@@ -72,12 +78,11 @@ object Redis { ...@@ -72,12 +78,11 @@ object Redis {
pRc4.withClient { client => pRc4.withClient { client =>
contentFuture.foreach { seq => contentFuture.foreach { seq =>
val idPairs = seq.map(c => (c.id, c.serviceId.getOrElse("-1"))) val idPairs = seq.map(c => (c.id, c.serviceId.getOrElse("-1")))
println(idPairs) val a = write(idPairs)
println(a)
if (idPairs.size > 0) { if (idPairs.size > 0) {
client.del(key) client.del(key)
idPairs.foreach { pair => client.set(key, a)
client.rpush(key, pair)
}
} }
} }
} }
......
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