类 DefaultRedisCacheWriter

java.lang.Object
com.sie.mbm.mom.framework.cache.DefaultRedisCacheWriter
所有已实现的接口:
org.springframework.data.redis.cache.CacheStatisticsProvider, org.springframework.data.redis.cache.RedisCacheWriter

public class DefaultRedisCacheWriter extends Object implements org.springframework.data.redis.cache.RedisCacheWriter
RedisCacheWriter implementation capable of reading/writing binary data from/to Redis in standalone and cluster environments. Works upon a given RedisConnectionFactory to obtain the actual RedisConnection.
DefaultRedisCacheWriter can be used in locking or non-locking mode. While non-locking aims for maximum performance it may result in overlapping, non atomic, command execution for operations spanning multiple Redis interactions like putIfAbsent. The locking counterpart prevents command overlap by setting an explicit lock key and checking against presence of this key which leads to additional requests and potential command wait times.
  • 字段详细资料

    • connectionFactory

      private final org.springframework.data.redis.connection.RedisConnectionFactory connectionFactory
    • sleepTime

      private final Duration sleepTime
  • 构造器详细资料

    • DefaultRedisCacheWriter

      public DefaultRedisCacheWriter(org.springframework.data.redis.connection.RedisConnectionFactory connectionFactory)
      参数:
      connectionFactory - must not be null.
    • DefaultRedisCacheWriter

      private DefaultRedisCacheWriter(org.springframework.data.redis.connection.RedisConnectionFactory connectionFactory, Duration sleepTime)
      参数:
      connectionFactory - must not be null.
      sleepTime - sleep time between lock request attempts. Must not be null. Use Duration.ZERO to disable locking.
  • 方法详细资料

    • put

      public void put(String name, byte[] key, byte[] value, @Nullable Duration ttl)
      指定者:
      put 在接口中 org.springframework.data.redis.cache.RedisCacheWriter
    • store

      public CompletableFuture<Void> store(String name, byte[] key, byte[] value, Duration ttl)
      Store the given key/value pair asynchronously to Redis and set the expiration time if defined.

      This operation is non-blocking.

      指定者:
      store 在接口中 org.springframework.data.redis.cache.RedisCacheWriter
      参数:
      name - cache name must not be null.
      key - key for the cache entry. Must not be null.
      value - value stored for the key. Must not be null.
      ttl - optional expiration time. Can be null.
      从以下版本开始:
      3.2
    • get

      public byte[] get(String name, byte[] key)
      指定者:
      get 在接口中 org.springframework.data.redis.cache.RedisCacheWriter
    • retrieve

      public CompletableFuture<byte[]> retrieve(String name, byte[] key, Duration ttl)
      Asynchronously retrieves the value to which the
      引用无效
      RedisCache
      maps the given byte[] key setting the TTL expiration for the cache entry.

      This operation is non-blocking.

      指定者:
      retrieve 在接口中 org.springframework.data.redis.cache.RedisCacheWriter
      参数:
      name - String with the name of the
      引用无效
      RedisCache
      .
      key - byte[] key mapped to the value in the
      引用无效
      RedisCache
      .
      ttl - Duration specifying the expiration timeout for the cache entry.
      返回:
      the value to which the
      引用无效
      RedisCache
      maps the given byte[] key.
      从以下版本开始:
      3.2
    • putIfAbsent

      public byte[] putIfAbsent(String name, byte[] key, byte[] value, @Nullable Duration ttl)
      指定者:
      putIfAbsent 在接口中 org.springframework.data.redis.cache.RedisCacheWriter
    • remove

      public void remove(String name, byte[] key)
      删除,原来是删除指定的键,目前修改为既可以删除指定键的数据,也是可以删除某个前缀开始的所有数据
      指定者:
      remove 在接口中 org.springframework.data.redis.cache.RedisCacheWriter
      参数:
      name -
      key -
    • clean

      public void clean(String name, byte[] pattern)
      指定者:
      clean 在接口中 org.springframework.data.redis.cache.RedisCacheWriter
    • clearStatistics

      public void clearStatistics(String s)
      指定者:
      clearStatistics 在接口中 org.springframework.data.redis.cache.RedisCacheWriter
    • withStatisticsCollector

      public org.springframework.data.redis.cache.RedisCacheWriter withStatisticsCollector(org.springframework.data.redis.cache.CacheStatisticsCollector cacheStatisticsCollector)
      指定者:
      withStatisticsCollector 在接口中 org.springframework.data.redis.cache.RedisCacheWriter
    • lock

      void lock(String name)
      Explicitly set a write lock on a cache.
      参数:
      name - the name of the cache to lock.
    • unlock

      void unlock(String name)
      Explicitly remove a write lock from a cache.
      参数:
      name - the name of the cache to unlock.
    • doLock

      private Boolean doLock(String name, org.springframework.data.redis.connection.RedisConnection connection)
    • doUnlock

      private Long doUnlock(String name, org.springframework.data.redis.connection.RedisConnection connection)
    • doCheckLock

      boolean doCheckLock(String name, org.springframework.data.redis.connection.RedisConnection connection)
    • isLockingCacheWriter

      private boolean isLockingCacheWriter()
      返回:
      true if RedisCacheWriter uses locks.
    • execute

      private <T> T execute(String name, Function<org.springframework.data.redis.connection.RedisConnection,T> callback)
    • executeLockFree

      private void executeLockFree(Consumer<org.springframework.data.redis.connection.RedisConnection> callback)
    • checkAndPotentiallyWaitUntilUnlocked

      private void checkAndPotentiallyWaitUntilUnlocked(String name, org.springframework.data.redis.connection.RedisConnection connection)
    • shouldExpireWithin

      private static boolean shouldExpireWithin(@Nullable Duration ttl)
    • createCacheLockKey

      private static byte[] createCacheLockKey(String name)
    • getCacheStatistics

      public org.springframework.data.redis.cache.CacheStatistics getCacheStatistics(String s)
      指定者:
      getCacheStatistics 在接口中 org.springframework.data.redis.cache.CacheStatisticsProvider