Class RedisKeyValueTemplate

java.lang.Object
org.springframework.data.keyvalue.core.KeyValueTemplate
org.springframework.data.redis.core.RedisKeyValueTemplate
All Implemented Interfaces:
Aware, DisposableBean, ApplicationEventPublisherAware, KeyValueOperations

public class RedisKeyValueTemplate extends KeyValueTemplate
Redis specific implementation of KeyValueTemplate.
Since:
1.7
Author:
Christoph Strobl, Mark Paluch
  • Constructor Details

  • Method Details

    • getConverter

      public RedisConverter getConverter()
      Obtain the underlying redis specific EntityConverter.
      Returns:
      never null.
      Since:
      2.1
    • getMappingContext

      public RedisMappingContext getMappingContext()
      Specified by:
      getMappingContext in interface KeyValueOperations
      Overrides:
      getMappingContext in class KeyValueTemplate
    • find

      public <T> List<T> find(RedisCallback<?> callback, Class<T> type)
      Retrieve entities by resolving their ids and converting them into required type.
      The callback provides either a single id or an Iterable of ids, used for retrieving the actual domain types and shortcuts manual retrieval and conversion of ids via RedisTemplate.
       
       List<RedisSession> sessions = template.find(new RedisCallback<Set<byte[]>>() {
         public Set<byte[]< doInRedis(RedisConnection connection) throws DataAccessException {
           return connection
             .sMembers("spring:session:sessions:securityContext.authentication.principal.username:user"
               .getBytes());
         }
       }, RedisSession.class);
       
       
      Parameters:
      callback - provides the to retrieve entity ids. Must not be null.
      type - must not be null.
      Returns:
      empty list if not elements found.
    • insert

      public <T> T insert(Object id, T objectToInsert)
      Specified by:
      insert in interface KeyValueOperations
      Overrides:
      insert in class KeyValueTemplate
    • update

      public <T> T update(T objectToUpdate)
      Specified by:
      update in interface KeyValueOperations
      Overrides:
      update in class KeyValueTemplate
    • update

      public <T> T update(Object id, T objectToUpdate)
      Specified by:
      update in interface KeyValueOperations
      Overrides:
      update in class KeyValueTemplate
    • doPartialUpdate

      protected void doPartialUpdate(PartialUpdate<?> update)