Spring Using Redis @Cacheable

Can anyone suggest a Redis example (NoSQL DB) for type Collection? Usually we use the following (in Spring):

@Cacheable(value = "PRODUCT", key = "#productId" ) 
public Map<String,Object> findProduct(String productId, String productName)
 { return map; } 

which stores the key and value as a String, but I need:

public Map<RestaurantId,Set<Order>>find(String RestaurantId, String productName){ return map; }
+4
source share
2 answers

Make sure your objects are Serializable, and then just use Spring Redis cache abstraction data ( link 2015)

An example is copied from the above documentation:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:cache="http://www.springframework.org/schema/cache"
  xmlns:c="http://www.springframework.org/schema/c"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

  <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
        p:use-pool="true"/>

  <!-- redis template definition -->
  <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
    p:connection-factory-ref="jedisConnectionFactory"/>

  <!-- turn on declarative caching -->
  <cache:annotation-driven />

  <!-- declare Redis Cache Manager -->
  <bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager" c:template-ref="redisTemplate"/>
</beans>
+4
source

You can use the Redisson framework, which provides Spring Cache .

+1
source

All Articles