diff --git a/src/main/scala/com/redislabs/provider/redis/ConnectionPool.scala b/src/main/scala/com/redislabs/provider/redis/ConnectionPool.scala index 22bfe897..f5322f29 100644 --- a/src/main/scala/com/redislabs/provider/redis/ConnectionPool.scala +++ b/src/main/scala/com/redislabs/provider/redis/ConnectionPool.scala @@ -23,7 +23,7 @@ object ConnectionPool { poolConfig.setMinEvictableIdleTimeMillis(60000) poolConfig.setTimeBetweenEvictionRunsMillis(30000) poolConfig.setNumTestsPerEvictionRun(-1) - new JedisPool(poolConfig, re.host, re.port, re.timeout, re.auth, re.dbNum) + new JedisPool(poolConfig, re.host, re.port, re.timeout, re.auth, re.dbNum, re.ssl) } ) var sleepTime: Int = 4 diff --git a/src/main/scala/com/redislabs/provider/redis/RedisConfig.scala b/src/main/scala/com/redislabs/provider/redis/RedisConfig.scala index 57c2e0a6..e836d4ed 100644 --- a/src/main/scala/com/redislabs/provider/redis/RedisConfig.scala +++ b/src/main/scala/com/redislabs/provider/redis/RedisConfig.scala @@ -11,23 +11,24 @@ import scala.collection.JavaConversions._ /** * RedisEndpoint represents a redis connection endpoint info: host, port, auth password - * db number, and timeout + * db number, timeout and ssl mode * * @param host the redis host or ip * @param port the redis port * @param auth the authentication password * @param dbNum database number (should be avoided in general) + * @param ssl true to enable SSL connection. Defaults to false */ case class RedisEndpoint(host: String = Protocol.DEFAULT_HOST, port: Int = Protocol.DEFAULT_PORT, auth: String = null, dbNum: Int = Protocol.DEFAULT_DATABASE, - timeout: Int = Protocol.DEFAULT_TIMEOUT) + timeout: Int = Protocol.DEFAULT_TIMEOUT, + ssl: Boolean = false) extends Serializable { /** - * Constructor from spark config. set params with spark.redis.host, spark.redis.port, spark.redis.auth and - * spark.redis.db + * Constructor from spark config. set params with spark.redis.host, spark.redis.port, spark.redis.auth, spark.redis.db and spark.redis.ssl * * @param conf spark context config */ @@ -37,23 +38,25 @@ case class RedisEndpoint(host: String = Protocol.DEFAULT_HOST, conf.getInt("spark.redis.port", Protocol.DEFAULT_PORT), conf.get("spark.redis.auth", null), conf.getInt("spark.redis.db", Protocol.DEFAULT_DATABASE), - conf.getInt("spark.redis.timeout", Protocol.DEFAULT_TIMEOUT) + conf.getInt("spark.redis.timeout", Protocol.DEFAULT_TIMEOUT), + conf.getBoolean("spark.redis.ssl", false) ) } /** * Constructor with Jedis URI * - * @param uri connection URI in the form of redis://:$password@$host:$port/[dbnum] + * @param uri connection URI in the form of redis://:$password@$host:$port/[dbnum]. Use "rediss://" scheme for redis SSL */ def this(uri: URI) { - this(uri.getHost, uri.getPort, JedisURIHelper.getPassword(uri), JedisURIHelper.getDBIndex(uri)) + this(uri.getHost, uri.getPort, JedisURIHelper.getPassword(uri), JedisURIHelper.getDBIndex(uri), + Protocol.DEFAULT_TIMEOUT, uri.getScheme == RedisSslScheme) } /** * Constructor with Jedis URI from String * - * @param uri connection URI in the form of redis://:$password@$host:$port/[dbnum] + * @param uri connection URI in the form of redis://:$password@$host:$port/[dbnum]. Use "rediss://" scheme for redis SSL */ def this(uri: String) { this(URI.create(uri)) diff --git a/src/main/scala/com/redislabs/provider/redis/package.scala b/src/main/scala/com/redislabs/provider/redis/package.scala index 260d5590..1f1ffce4 100644 --- a/src/main/scala/com/redislabs/provider/redis/package.scala +++ b/src/main/scala/com/redislabs/provider/redis/package.scala @@ -1,7 +1,7 @@ package com.redislabs.provider package object redis extends RedisFunctions { - + val RedisSslScheme: String = "rediss" val RedisDataTypeHash: String = "hash" val RedisDataTypeString: String = "string" }