[Scala] Scala操作Redis

注意点:需要带scala和redis的jar包

另外,需要加入redis的jar包并在提交时体现

package com.huawei.bigdata.spark.examples
import java.util.HashSet;
import java.util.Set;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
import com.huawei.medis.BatchException;
import com.huawei.medis.ClusterBatch;
/**
Run Command:
nohup spark-submit --jars lib5/jredisclient-0.0.1.jar,lib5/commons-pool2-2.3.jar --class com.huawei.bigdata.spark.examples.scalaRedis --master yarn-client /home/ap/dip/appjob/shelljob/dzyh/jobScala/ebda_mllib.jar scala_Redis > scala_redis.log &
**/
object scalaRedis {
def main (args: Array[String]) {
if (args.length < 1) { System.err.println("Usage: CollectFemaleInfo")
System.exit(1)
}
/**STEP1: Variables Initialized**/
val jedisClusterNodes = new HashSet[HostAndPort]
//Jedis Cluster will attempt to discover cluster nodes automatically
jedisClusterNodes.add(new HostAndPort("128.196.116.74", 22400))
jedisClusterNodes.add(new HostAndPort("128.196.116.75", 22400))
jedisClusterNodes.add(new HostAndPort("128.196.116.76", 22400))
/**STEP3: Data Analysis**/
val jc: JedisCluster = new JedisCluster(jedisClusterNodes)
jc.hset("tbl_scala_redis", "ID01", "Zacks")
var result = jc.hget("tbl_scala_redis", "ID01")
print("tbl_scala_redis ID01 is " )
println(result)
}
}
分类上一篇:     分类下一篇:

Leave a Reply