この場合、KV ストア (Redis) からデータを読み取っています。返されるデータは次の形式です。
{ "key1":"value1", "key2":"value2", "key3":"value3" ...}
キーはString
で、値はInt
です。に変換したいMap[String,Int]
json4s JSON APIを調べたところ、現在のコードは次のようになっています。これを行うためのより良い/より簡単な/よりクリーンな方法はありますか?
//send a async query to Redis to
val queryFuture = redis.zrangebyscore[String](tablename, keymin, keymax )
queryFuture.onComplete {
case Success(datarows) =>
println(s"Got %d rows of type %s for the query successfully".format(datarows.length))
val jsonrows = for { x <- datarows.toList }
yield parse(x)
println("Got json rows %d".format(jsonrows.size))
val mapdata = jsonrows.map(x => x.extract[Map[String,String]]).map( x => x.mapValues(_.toInt))
//need to do something with this data now
case Failure(y) =>
println(s" there was some failure in getting the data from Redis")
}