问题标签 [spring-data-redis]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
4923 浏览

spring-boot - 如何使用 spring-data-redis 连接到多个 redis 实例

我正在尝试将一个 springboot 应用程序连接到 2 个不同的 redis 实例:一个用作数据库,一个仅用作缓存。我添加了不同名称的不同连接工厂和 redis 模板,并使用 @Qualifier 链接它们。我试图从自动配置中禁用 RedisAutoConfiguration 类,但没有任何效果。

我总是收到这个错误:

包装者:org.springframework.beans.factory.UnsatisfiedDependencyException:在类路径资源 [org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration$RedisConfiguration.class] 中定义名称为“redisTemplate”的 bean 创建错误:通过不满足的依赖关系表示[org.springframework.data.redis.connection.RedisConnectionFactory] ​​类型索引为 0 的构造函数参数:没有定义 [org.springframework.data.redis.connection.RedisConnectionFactory] ​​类型的限定 bean:预期单个匹配 bean,但找到了 2: redisCacheFactory,redisJitFactory; 嵌套异常是 org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有定义 [org.springframework.data.redis.connection.RedisConnectionFactory] ​​类型的合格 bean:预期单个匹配 bean,但找到 2:redisCacheFactory,

你能给我任何关于如何实现这一点的提示吗?

提前致谢!

0 投票
2 回答
1176 浏览

transactions - Redis: Transaction with multiple keys

I'm using Spring Data Redis. In Redis the basic data models are

job: Hash that contains a job's data.

queue: List that contains job ids serving as a queue.

New job will be saved in job hash and it will be pushed to queue. We have multiple worker clients pooling the queue to consume new job id by popping the id and read details from hash.

Now I'm trying to work out a new feature that certain worker can only consume certain jobs, based on some flags within job data. The problem is worker will only know if it can consume the job after reading its details, but not at the moment of taking the id from the queue.

I originally thought I can put this sequence of operations into a transaction,

  1. Peek the queue.
  2. Read job details from hash and check if consumable.
  3. If yes, take its id from queue, otherwise do nothing.

However this kind of transaction involves both queue and hash data. After reading Redis's transaction support I'm not sure if this is achievable. Please help to advise what approach should I take.

0 投票
0 回答
1998 浏览

spring-session - 使用spring-data-redis时如何配置redis-cluster

我尝试使用 Spring Session 和 Redis Cluster 但收到类似 Caused by: redis.clients.jedis.exceptions.JedisConnectionException: 无法从池中获取资源的错误。

但是,如果我只使用 Jedis 客户端,它会成功连接。同时,哨兵连接也有效。

我的 application.yml 看起来像:

我的 POM 文件是

Redis 集群信息:

0 投票
1 回答
475 浏览

redis - 无法在 spring-data-redis 事务中查询列表

嗨,大家好。我的 redis 中有一个名为“mylist”的列表,其大小为 50。

但是当我运行这段代码时,我无法得到我想要的。

字段“dataList”为空,但是,值为“Hello World”的“mykey”已保留在我的 redis 中。

那么如何在 spring-data-redis 事务中获取我的列表数据呢?非常感谢。

0 投票
3 回答
2943 浏览

spring-cache - 在单个方法上调用 @CacheEvict 和 @Cacheable 注释?

我试图在一个方法上调用 @CacheEvict 和 @Cacheable 注释。

在调用@CacheEvict 时,我想删除特定键的缓存数据,并且我想再次缓存方法响应的新数据。但它没有缓存新数据?而且它没有给出任何错误?

0 投票
0 回答
402 浏览

redis - spring-data-redis 集群恢复问题

我们正在运行一个 7 节点的 redis 集群,所有节点都作为主节点(没有从节点复制)。我们将其用作内存缓存,因此我们在 redis.conf 中注释掉了所有保存,并且我们在 redis.conf 中有以下其他非默认值:

这个集群的客户端是一个 spring-boot rest api 应用程序,使用 spring-data-redis 和 jedis 作为驱动程序。我们主要使用spring缓存注解。

前几天我们遇到了一个问题,其中一位大师倒下了一段时间。在 7 节点集群中,当单个主服务器宕机时,我们注意到涉及 redis 的 api 调用的平均响应时间显着增加,这是我所预料的。

当宕机的 master 重新上线并重新加入集群时,我们的响应时间出现了巨大的峰值。通过 newrelic,我可以看到该应用程序开始进行大量的 redis 集群调用(newrelic 没有告诉我正在使用哪个集群子命令)。我们正常的平均响应时间约为 5 毫秒;在此期间,它上升到 800 毫秒,我们有一些缓慢的示例事务,耗时 > 70 秒。在所有应用 jvm 上,我看到在此期间活动线程的数量从正常的 8-9 跃升至 300 左右。我们已将 tomcat http 线程池配置为最多允许 400 个线程。大约 3 分钟后,问题自行解决,但我现在有人质疑我们选择的缓存解决方案的稳定性。Newrelic 没有提供任何关于长请求的额外时间花费在哪里的洞察力(它'

我已经尝试通过针对开发环境运行一些 jmeter 负载测试来进行重现,虽然我在重新连接 redis-cluster master 时看到了一些适度的响应时间峰值,但我没有看到任何接近我们在生产中看到的东西. 我也遇到过https://github.com/xetorthio/jedis/issues/1108,但我没有从中获得任何有用的见解。我尝试将 spring.redis.cluster.max-redirects 从默认的 5 减少到 0,这似乎对我的负载测试结果没有太大影响。我也不确定更改对我的用例有多合适。

0 投票
1 回答
4142 浏览

java - 将 JedisPoolConfig testOnBorrow 设置为 false

因此,目前在我的 JedisPoolConfig bean 中,我将参数 testOnBorrow 设置为 true。看来这检索资源较慢。

有一个场景,Jedis 花了 30 分钟从 Redis 中检索资源(在获取资源或脱离之前多次调用方法(redis.clients.jedis.BinaryJedis:exists:144 和 java.lang.Thread:sleep) )。

我认为我可以做的是将参数 testOnBorrow 设置为 false 以防止在读取资源之前对 Redis 进行 PING 调用。

所以,我的问题(我真的希望我能得到答案)是:

  1. “设置此参数对我的应用程序有什么影响”?
  2. “这个方案真的有效吗?”
  3. “这个阅读慢的问题有没有更好的解决方案?”
0 投票
1 回答
898 浏览

spring - 使用 Spring @Cacheable 和 SimpleKeyGenerator 时可能会发生冲突

当我使用@Cacheable和调用具有相同参数的不同方法时,它会生成相同的密钥。 SimpleKeyGenerator生成的没有缓存名称的密钥。

我使用 spring-boot 1.3.2 和 spring 4.2.4。

这是一个示例:

并运行测试:

那么,有没有办法解决这个问题呢?非常感谢。

更新

这是我的CacheManager配置。

0 投票
0 回答
347 浏览

java - Jedis waitForLock 时间限制或覆盖

在我对 Jedis 从 Redis 获取资源时遇到的问题进行调查时,我发现 Spring Data Redis 有一个名为 waitForLock 的方法,当 Redis 中存在缓存锁键名时,该方法会进入 Thread.sleep 的交互。这个迭代一直持续到缓存锁定键不在 Redis 中,所以它可能需要很长时间(在我的例子中是 27 分钟)。

是否存在可供我覆盖此行为的配置,即创建一个限制,Spring Data Redis 将在抛出异常之前检查此锁定键。

或者除了配置设置之外还有其他方法。

0 投票
1 回答
1283 浏览

spring-boot - 从 Spring Actuator 获取 Spring Session 信息

我有一个基于弹簧云的应用程序,它将弹簧会话存储在 redis 中。它使用带有嵌入式 tomcat 的 Spring Boot。

使用弹簧执行器时,/metrics 端点不会返回任何有价值的信息。httpsessions.active 设置为 0,httpsessions.max 设置为 -1。

我猜这是因为 spring 用自己的 spring session 实现替换了 httpsession 实现。

有没有办法从某个端点访问这些信息?最好使用 JMX,但不是强制性的。

谢谢。