package com.*****
import org.apache.spark.{SparkConf, SparkContext}
import com.redislabs.provider.redis._
/**
* \* Created By ****.
* \* User: ****
* \* Date: 2019-09-26
* \* Time: 18:26
* \* To change this template use File | Settings | File Templates.
* \* Description:
* \*/
object Test {
def main(args: Array[String]) {
if (args.length < 1) {
System.err.println("Usage: <file>")
System.exit(1)
}
val conf = new SparkConf()
conf.set("redis.host","xx.xxx.xx.xxx")
conf.set("redis.port","6379")
// conf.set("redis.db","0")
val sc = new SparkContext(conf)
val data = Array(("key1", "v1"), ("key2", "world"), ("key3", "hello"), ("key4", "Hong"), ("key5", "Kong"))
val distData = sc.parallelize(data)
sc.toRedisHASH(distData,"foo")
val stringRDD = sc.fromRedisHash(Array("foo")).collect().foreach(println(_))
val stringRDD1 = sc.fromRedisKV(Array("aaa","bbb")).map(x=>(x._1,x._2.toString)).collect().foreach(println(_))
sc.stop()
}
} |