debasishg / scala-redis

A scala library for connecting to a redis server, or a cluster of redis nodes using consistent hashing on the client side.
1.02k stars 219 forks source link

How to use SSL Context to connect to Redis instance on AWS Elasticache with Encryption In-Transit enabled #267

Closed saragallagherpdgc closed 2 years ago

saragallagherpdgc commented 3 years ago

I am unable to properly connect to a Redis Instance on Elasticache with Encryption In-Transit enabled. I can connect to the redis client on the read. However on the write nothing happens, my job just hangs and eventually times out. The elasticache does not have any authentication. @mattusifer I saw that you wrote the code for SSL Context, if you could provide any insight that'd be great. Thanks!

object RedisClient { var writeHost: String = "HOST" var readHost: String = "HOST" var port: Int = 6379 var keyTTL: Int = 3600 var maxIdle: Int = 8 var database: Int = 0 var secret: Option[Any] = None var timeout: Int = 300000 var maxConnections: Int = RedisClientPool.UNLIMITED_CONNECTIONS var poolWaitTimeout: Int = 3000

private val sslContext = SSLContext.getInstance("TLS")

private lazy val writePool = new RedisClientPool(writeHost, port, maxIdle, database, secret, timeout, maxConnections, poolWaitTimeout, Some(sslContext)) private lazy val readPool = new RedisClientPool(readHost, port, maxIdle, database, secret, timeout, maxConnections, poolWaitTimeout)

def getCount(id: String): Option[String] = { readPool.withClient(client => { client.get(id) }) }

def setCount(id: String, count: String): Boolean = writePool.withClient(client => { client.setex(id, keyTTL, count) })

def close(): Unit = { readPool.close() writePool.close() } }

zizzle6717 commented 2 years ago

Try something like this new RedisClient("your-aws-endpoint", 6379, sslContext = Some(SSLContext.getDefault()), secret = "your-auth-secret")