我有一个场景,应用程序需要从 redis 中获取每个请求大约 80 次的操作。当我对该应用程序发出 1 个请求时,它会在不到 1 秒的时间内给出响应,但是当请求大小增加到 100 时,redissonClient 开始表现缓慢,大约需要 13 秒才能获取 250 条记录。
我是 Redis 的新手,不确定这是否是默认设置。虽然我在一些文章中发现 redis 可以在 1 秒内在 1 个节点上处理数百万个操作。我们的 Redis 服务器目前在 1 个节点上运行。
下面是redis的配置:
{
"singleServerConfig": {
"idleConnectionTimeout": 10000,
"pingTimeout": 1000,
"connectTimeout": 10000,
"timeout": 2000,
"retryAttempts": 3,
"retryInterval": 1500,
"reconnectionTimeout": 2000,
"failedAttempts": 3,
"password": null,
"subscriptionsPerConnection": 5,
"clientName": null,
"address": "redis://172.18.17.207:6379",
"subscriptionConnectionMinimumIdleSize": 1,
"subscriptionConnectionPoolSize": 50,
"connectionMinimumIdleSize": 32,
"connectionPoolSize": 100,
"database": 0,
"dnsMonitoringInterval": 5000
},
"threads": 128,
"nettyThreads": 128,
"codec": null,
"useLinuxNativeEpoll": false
}
下面是我在启动时如何实例化 redisson 客户端:
try {
Config config = Config.fromJSON(CommonConstants.REDIS_SINGLE_CONFIG_JSON_FILE);
redisClient = Redisson.create(config);
} catch (IOException e) {
log.error(null, "Error establishing connection to Redis Cluster!", e);
}
下面是我获取记录的方式:
public List<Map<String, String>> fetch(List<String> ids) {
return ids.stream().map(id -> {
Map<String, String> m = redisClient.getMapCache(id);
return m;
}).collect(Collectors.toList());
}
我怀疑我错误地配置了 redis 客户端,但无法弄清楚那是什么。
非常感谢任何帮助/帮助。
谢谢
最佳答案
Stream 使用 RMapCache 对象提供的迭代器。它默认只获取 10 个元素,我建议您改用 RMapCache.readAllMap
方法。
关于java - Redis 获取需要时间使用 redisson,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53298972/