正常redis是没有数据库的概念的,但是当redis变成集群的时候,它是可以设置数据库的。(其实也就是开辟一块索引)
但是以前接触的spark用rediscontext的方式,只能设置IP和端口号。
只能在网上找相关资料。才发现之前找的库已经更新了。里面就提供了这样的参数。(https://github.com/RedisLabs/spark-redis)
在该网址中已经介绍:
sc = new SparkContext(new SparkConf() .setMaster("local") .setAppName("myApp") // initial redis host - can be any node in cluster mode .set("redis.host", "localhost") // initial redis port .set("redis.port", "6379") // optional redis AUTH password .set("redis.auth", "") )
The supported configuration keys are:
redis.host
- host or IP of the initial node we connect to. The connector will read the cluster topology from the initial node, so there is no need to provide the rest of the cluster nodes.redis.port
- the inital node's TCP redis port.redis.auth
- the initial node's AUTH passwordredis.db
- optional DB number. Avoid using this, especially in cluster mode.
于是实验,果然成功!