我正在尝试将所有值设置为fieldValueMap以便将其提取到Redis,但似乎该部分不起作用。
kafkaInputStream.foreachRdd { (rdd, time) =>
val redisSink = new RedisSink(streamingConfig.redisClusterZone)
val fieldValueMap: mutable.Map[String, String] = redisSink.getJedisCluster.hgetAll("mykey").asScala
rdd.mapPartitions(_.map(record => {
val value: JValue = JsonMethods.parse(record.value)
val errString = value \ "errString"
/** redis */
val index = if (!fieldValueMap.contains(errString)) {
fieldValueMap += (errString -> fieldValueMap.size.toString)
fieldValueMap.size.toString
} else {
fieldValueMap(errString)
}
val output = ("errString" -> errString) ~ ("index" -> index)
output
}))
fieldValueMap.foreach { case (k, v) =>
redisSink.getJedisCluster.hsetnx("infotech-access", k, v)
}
redisSink.closeJedis()
}