spring-data-redis

spring-data-redis Jackson serialization

喜夏-厌秋 提交于 2019-12-04 16:44:19
I'm attempting to use the Jackson serialization feature of spring-data-redis. I am building a ObjectMapper and using the GenericJackson2JsonRedisSerializer as the serializer for the redisTemplate: @Configuration public class SampleModule { @Bean public ObjectMapper objectMapper() { return Jackson2ObjectMapperBuilder.json() .serializationInclusion(JsonInclude.Include.NON_NULL) // Don’t include null values .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) //ISODate .build(); } @Bean public RedisTemplate getRedisTemplate(ObjectMapper objectMapper, RedisConnectionFactory

How to build dynamic queries with Spring Data Redis Repositories?

落爺英雄遲暮 提交于 2019-12-04 15:51:23
I'm testing Redis with spring-data-redis using repositories like this: public interface CreditCardRepository extends CrudRepository<CreditCard, String>{ List<CreditCard> findByIssuer(String issuer); List<CreditCard> findByCreditNetwork(String creditNetwork); List<CreditCard> findByCreditNetworkAndIssuer(String creditNetwork, String issuer); } Above methods will query over Redis structures like: creditcard:creditNetwork:mastercard creditcard:creditNetwork:visa creditcard:issuer:company1 creditcard:issuer:company2 Right now my CreditCard object contains two attributes (issuer, network and the id

Spring-data-redis @Cacheable java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String

久未见 提交于 2019-12-04 10:25:00
I want to use spring-data-redis to caching data in my spring boot app.But it always says cast exception.I googled for some time but have no ideas.Please help me.thanks,any suggestions are greateful! Here is my RedisConfiguation: @Configuration @EnableCaching public class RedisConfiguration extends CachingConfigurerSupport { @Value("${spring.redis.host}") private String host; @Value("${spring.redis.port}") private String port; @Value("${spring.redis.expire}") private String expire; @Value("${spring.redis.database}") private String databaseIndex; @Value("${spring.redis.password}") private String

NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute

China☆狼群 提交于 2019-12-03 12:32:29
I am trying to use spring-data-redis in a spring-boot application to work with redis. I am creating JedisConnectionFactory as follows: RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(); configuration.setHostName("localhost"); configuration.setPort(6379); JedisConnectionFactory connectionFactory = new JedisConnectionFactory(configuration); It throws the exception: Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional; at org.springframework

Redis集成(spring-data-redis)

﹥>﹥吖頭↗ 提交于 2019-12-02 02:52:42
1.pom.xml引入 demo-base引入 说明: jedis :redis官网对java语言提供支持。可单独使用。 spring-data-redis :spring对jedis集成。 2.配置 在配置在demo-web下 redis.properties: redis.host=127.0.0.1 redis.port=6379 redis.timeout=15000 redis.password= redis.database=2 spring-mvc.xml <!--spring最多加载一个context:property-placeholder--> <!--如果去掉jdbc.properties加载,demo-web启动会提示找不对应变量值--> <context:property-placeholder location="classpath:redis.properties,classpath*:jdbc.properties"/> <!--将spring-redis引入spring中--> <import resource="spring-redis.xml"/> spring-redis.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework

How to config redis-cluster when use spring-data-redis 1.7.0.M1

醉酒当歌 提交于 2019-12-01 20:30:43
问题 I use spring-data-redis version 1.7.0.M1,and jedis version 2.8.0 Here is my configuration <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"> <property name="connectionFactory" ref="redisConnectionFactory"></property> <property name="keySerializer"> <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/> </property> <property name="hashKeySerializer"> <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/> <

How to get same rank for same scores in Redis' ZRANK?

若如初见. 提交于 2019-12-01 18:34:22
If I have 5 members with scores as follows a - 1 b - 2 c - 3 d - 3 e - 5 ZRANK of c returns 2, ZRANK of d returns 3 Is there a way to get same rank for same scores? Example: ZRANK c = 2, d = 2, e = 3 If yes, then how to implement that in spring-data-redis? Any real solution needs to fit the requirements, which are kind of missing in the original question. My 1st answer had assumed a small dataset, but this approach does not scale as dense ranking is done (e.g. via Lua) in O(N) at least. So, assuming that there are a lot of users with scores, the direction that for_stack suggested is better, in

How to config redis-cluster when use spring-data-redis 1.7.0.M1

南楼画角 提交于 2019-12-01 18:28:21
I use spring-data-redis version 1.7.0.M1,and jedis version 2.8.0 Here is my configuration <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"> <property name="connectionFactory" ref="redisConnectionFactory"></property> <property name="keySerializer"> <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/> </property> <property name="hashKeySerializer"> <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/> </property> <property name="valueSerializer"> <bean class="org.springframework.data.redis.serializer

Redis - How to configure custom conversions

瘦欲@ 提交于 2019-12-01 15:27:53
问题 In spring-data-redis, How do we need configure custom converters that can be auto-wired/injected from Spring boot application or configuration. I read about @ReadingConverter and @WritingConverter from spring data redis documentation. From this documentation, it is not clear on how to configure them. https://github.com/spring-projects/spring-data-redis/blob/master/src/main/asciidoc/reference/redis-repositories.adoc#redis.repositories.indexes Does anyone know how to do it? 回答1: You have to

Caused by: java.lang.IllegalArgumentException: CONTAINING (1): [IsContaining, Containing, Contains]is not supported for redis query derivation - Redis

南笙酒味 提交于 2019-12-01 14:04:57
I'm developing Spring Boot + Redis example. In this example, I've developed some custom methods which pull details based on RoleName. For the below method userRepository.findByRole_RoleName("ADMIN") or userRepository.findByMiddleNameContaining("Li"); , we're getting the below exception. The reference URL: https://docs.spring.io/spring-data/keyvalue/docs/1.2.15.RELEASE/reference/html/ Could anyone please provider pointers ? All the other methods are working fine. But just this method causing the problems. I will post all the required code below for reference. Error: java.lang