scala - 连接到 Redis Elasticache 实例,启用了传输中加密,无需使用 Scala 进行身份验证
问题描述
我正在尝试连接到 AWS 上的 Elasticache Redis 实例,但遇到了一些麻烦...
禁用传输中加密时,我可以正常连接。但是,当它启用时,我遇到了问题。
我正在使用scala-redis,我可以在读取时连接到 redis 客户端。然而,在写入时没有任何反应,我的工作只是挂起并最终超时。elasticache 没有任何身份验证,我按照 scala-redis 中的测试示例建立 SSL 连接。
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 = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy(){
def isTrusted(arg0: Array[X509Certificate], arg1:String) = true
}).build()
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()
}
}
解决方案
推荐阅读
- python - 使用 scrapy 限制检索到的项目数
- php - php连续显示两条记录然后重复,从中间开始
- c# - 比较两个数字的相等性时出现意外错误
- c++ - 如何从类成员函数返回指针,例如 size_t * class :: function(); 并使用类析构函数 ~size_t*class::function();
- java - NetBeans 安装程序在“正在配置安装程序...”后以白屏关闭
- wso2 - WSO2 Identity Server 5.7.0 - 无法在主域下创建新角色
- python - Keras 二元分类器教程示例仅提供 50% 的验证准确度
- python - 将生成器与 tf.data 一起使用的最可扩展方式?tf.data 指南说 `from_generator` 的可扩展性有限
- sql - ORA-00979: 不是 GROUP BY 表达式 ORACLE
- java - 整数数组作为命令行参数以及其他命令