Class RedisOpsImpl
java.lang.Object
top.tangyh.basic.cache.repository.impl.RedisOpsImpl
- All Implemented Interfaces:
CacheOps,CachePlusOps
Redis Repository
redis 基本操作 可扩展,基本够用了
- Author:
- zuihou
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription为键 key 储存的数字值减去一。将 key 所储存的值减去减量 decrement 。删除指定的keydel(Collection<CacheKey> keys) 删除指定的key删除指定的key判断指定的key 是否存在为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除。<T> List<CacheResult<T>>find(Collection<CacheKey> keys) 根据keys获取对象voidflushDb()清空redis存储的数据<T> CacheResult<T>根据key获取对象<T> CacheResult<T>根据key获取对象<T> CacheResult<T>根据key获取对象 不存在时,调用function回调获取数据,并set进入,然后返回getCounter(CacheKey key, Function<CacheKey, Long> loader) 获取key中存放的Long值获取 RedisTemplate对象删除哈希表 key 中的一个或多个指定域,不存在的域将被忽略。hDel(CacheHashKey cacheHashKey) 删除哈希表 key 中的指定域,不存在的域将被忽略。hExists(CacheHashKey cacheHashKey) 检查给定域 field 是否存在于哈希表 hash 当中<T> CacheResult<T>hGet(CacheHashKey key, boolean... cacheNullValues) 返回哈希表 key 中给定域 field 的值。<T> CacheResult<T>hGet(CacheHashKey key, Function<CacheHashKey, T> loader, boolean... cacheNullValues) 返回哈希表 key 中给定域 field 的值。<K,V> Map<K, CacheResult<V>> hGetAll(CacheHashKey key) 返回哈希表 key 中,所有的域和值。<K,V> Map<K, CacheResult<V>> hGetAll(CacheHashKey key, Function<CacheHashKey, Map<K, V>> loader, boolean... cacheNullValues) 返回哈希表 key 中,所有的域和值。hIncrBy(CacheHashKey key, double increment) 为哈希表 key 中的域 field 的值加上增量 increment 。hIncrBy(CacheHashKey key, long increment) 为哈希表 key 中的域 field 的值加上增量 increment 。<HK> Set<HK>hKeys(CacheHashKey key) 返回哈希表 key 中的所有域。hLen(CacheHashKey key) 返回哈希表 key 中域的数量。voidhSet(CacheHashKey key, Object value, boolean... cacheNullValues) 将哈希表 key 中的域 field 的值设为 value 。<HV> List<CacheResult<HV>>hVals(CacheHashKey key) 返回哈希表 key 中所有域的值。为键 key 储存的数字值加上一。为键 key 储存的数字值加上increment。incrByFloat(CacheKey key, double increment) 为键 key 储存的数字值加上一。查找所有符合给定模式 pattern 的 key 。移除给定 key 的生存时间,将这个 key 从『易失的』(带生存时间 key )转换成『持久的』(一个不带生存时间、永不过期的 key )。以毫秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略。查找所有符合给定模式 pattern 的 key 。voidscanUnlink(String pattern) 查找所有符合给定模式 pattern 的 key ,并将其删除返回集合 key 的基数(集合中元素的数量)。void添加到带有 过期时间的 缓存返回集合 key 中的所有成员。<T> T移除并返回集合中的一个随机元素。移除集合 key 中的一个或多个 member 元素,不存在的 member 元素会被忽略。以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。返回 key 所储存的值的类型。
-
Constructor Details
-
RedisOpsImpl
-
-
Method Details
-
getRedisTemplate
获取 RedisTemplate对象 -
del
Description copied from interface:CacheOps删除指定的key -
del
Description copied from interface:CacheOps删除指定的key -
del
Description copied from interface:CacheOps删除指定的key -
exists
Description copied from interface:CacheOps判断指定的key 是否存在 -
set
Description copied from interface:CacheOps添加到带有 过期时间的 缓存 -
get
Description copied from interface:CacheOps根据key获取对象 -
get
Description copied from interface:CacheOps根据key获取对象 -
find
Description copied from interface:CacheOps根据keys获取对象 -
get
public <T> CacheResult<T> get(@NonNull CacheKey key, Function<CacheKey, ? extends T> loader, boolean... cacheNullValues) Description copied from interface:CacheOps根据key获取对象 不存在时,调用function回调获取数据,并set进入,然后返回 -
flushDb
public void flushDb()清空redis存储的数据 -
incr
Description copied from interface:CacheOps为键 key 储存的数字值加上一。 -
getCounter
Description copied from interface:CacheOps获取key中存放的Long值- Specified by:
getCounterin interfaceCacheOps- Parameters:
key- 一定不能为 null.loader- 加载- Returns:
- key中存储的的数字
-
incrBy
Description copied from interface:CacheOps为键 key 储存的数字值加上increment。 -
incrByFloat
Description copied from interface:CacheOps为键 key 储存的数字值加上一。- Specified by:
incrByFloatin interfaceCacheOps- Parameters:
key- 一定不能为 null.increment- 增量值- Returns:
- 返回键 key 在执行加一操作之后的值。
-
decr
Description copied from interface:CacheOps为键 key 储存的数字值减去一。 -
decrBy
Description copied from interface:CacheOps将 key 所储存的值减去减量 decrement 。 -
keys
Description copied from interface:CachePlusOps查找所有符合给定模式 pattern 的 key 。例子: KEYS * 匹配数据库中所有 key 。 KEYS h?llo 匹配 hello , hallo 和 hxllo 等。 KEYS a*cde 匹配 acde 和 aeeeeecde 等。 KEYS h[ae]llo 匹配 hello 和 hallo ,但不匹配 hillo 。
特殊符号用 \ 隔开
- Specified by:
keysin interfaceCachePlusOps- Parameters:
pattern- 表达式- Returns:
- 符合给定模式的 key 列表
-
scan
Description copied from interface:CachePlusOps查找所有符合给定模式 pattern 的 key 。例子: KEYS * 匹配数据库中所有 key 。 KEYS h?llo 匹配 hello , hallo 和 hxllo 等。 KEYS a*cde 匹配 acde 和 aeeeeecde 等。 KEYS h[ae]llo 匹配 hello 和 hallo ,但不匹配 hillo 。
特殊符号用 \ 隔开
- Specified by:
scanin interfaceCachePlusOps- Parameters:
pattern- 表达式- Returns:
- 符合给定模式的 key 列表
-
scanUnlink
Description copied from interface:CachePlusOps查找所有符合给定模式 pattern 的 key ,并将其删除例子: KEYS * 匹配数据库中所有 key 。 KEYS h?llo 匹配 hello , hallo 和 hxllo 等。 KEYS a*cde 匹配 acde 和 aeeeeecde 等。 KEYS h[ae]llo 匹配 hello 和 hallo ,但不匹配 hillo 。
特殊符号用 \ 隔开
- Specified by:
scanUnlinkin interfaceCachePlusOps- Parameters:
pattern- 表达式
-
expire
Description copied from interface:CachePlusOps为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除。- Specified by:
expirein interfaceCachePlusOps- Parameters:
key- 一定不能为 null.- Returns:
- 是否成功
-
persist
Description copied from interface:CachePlusOps移除给定 key 的生存时间,将这个 key 从『易失的』(带生存时间 key )转换成『持久的』(一个不带生存时间、永不过期的 key )。- Specified by:
persistin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.- Returns:
- 是否成功
-
type
Description copied from interface:CachePlusOps返回 key 所储存的值的类型。- Specified by:
typein interfaceCachePlusOps- Parameters:
key- 一定不能为 null.- Returns:
- none (key不存在)、string (字符串)、list (列表)、set (集合)、zset (有序集)、hash (哈希表) 、stream (流)、caffeine(内存)
-
ttl
Description copied from interface:CachePlusOps以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。- Specified by:
ttlin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.- Returns:
- 当 key 不存在时,返回 -2 。 当 key 存在但没有设置剩余生存时间时,返回 -1 。 否则,以秒为单位,返回 key 的剩余生存时间。
-
pTtl
Description copied from interface:CachePlusOps以毫秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。- Specified by:
pTtlin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.- Returns:
- 当 key 不存在时,返回 -2 。当 key 存在但没有设置剩余生存时间时,返回 -1 。否则,以毫秒为单位,返回 key 的剩余生存时间
-
hSet
Description copied from interface:CachePlusOps将哈希表 key 中的域 field 的值设为 value 。- Specified by:
hSetin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.value- 值cacheNullValues- 是否缓存空对象
-
hGet
Description copied from interface:CachePlusOps返回哈希表 key 中给定域 field 的值。- Specified by:
hGetin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.cacheNullValues- 是否缓存空值- Returns:
- 默认情况下返回给定域的值, 如果给定域不存在于哈希表中, 又或者给定的哈希表并不存在, 那么命令返回 nil
-
hGet
public <T> CacheResult<T> hGet(@NonNull CacheHashKey key, Function<CacheHashKey, T> loader, boolean... cacheNullValues) Description copied from interface:CachePlusOps返回哈希表 key 中给定域 field 的值。- Specified by:
hGetin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.loader- 加载器cacheNullValues- 是否缓存空值- Returns:
- 默认情况下返回给定域的值, 如果给定域不存在于哈希表中, 又或者给定的哈希表并不存在, 那么命令返回 nil
-
hExists
Description copied from interface:CachePlusOps检查给定域 field 是否存在于哈希表 hash 当中- Specified by:
hExistsin interfaceCachePlusOps- Parameters:
cacheHashKey- 一定不能为 null.- Returns:
- 是否存在
-
hDel
Description copied from interface:CachePlusOps删除哈希表 key 中的一个或多个指定域,不存在的域将被忽略。- Specified by:
hDelin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.fields- 一定不能为 null.- Returns:
- 删除的数量
-
hDel
Description copied from interface:CachePlusOps删除哈希表 key 中的指定域,不存在的域将被忽略。- Specified by:
hDelin interfaceCachePlusOps- Parameters:
cacheHashKey- 一定不能为 null.- Returns:
- 删除的数量
-
hLen
Description copied from interface:CachePlusOps返回哈希表 key 中域的数量。- Specified by:
hLenin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.- Returns:
- 哈希表中域的数量。
-
hIncrBy
Description copied from interface:CachePlusOps为哈希表 key 中的域 field 的值加上增量 increment 。- Specified by:
hIncrByin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.increment- 增量- Returns:
- 执行 HINCRBY 命令之后,哈希表 key 中域 field 的值
-
hIncrBy
Description copied from interface:CachePlusOps为哈希表 key 中的域 field 的值加上增量 increment 。- Specified by:
hIncrByin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.increment- 增量- Returns:
- 执行 HINCRBY 命令之后,哈希表 key 中域 field 的值
-
hKeys
Description copied from interface:CachePlusOps返回哈希表 key 中的所有域。- Specified by:
hKeysin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.- Returns:
- 所有的 filed
-
hVals
Description copied from interface:CachePlusOps返回哈希表 key 中所有域的值。- Specified by:
hValsin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.- Returns:
- 一个包含哈希表中所有值的表。
-
hGetAll
Description copied from interface:CachePlusOps返回哈希表 key 中,所有的域和值。 在返回值里,紧跟每个域名(field name)之后是域的值(value),所以返回值的长度是哈希表大小的两倍。- Specified by:
hGetAllin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.- Returns:
- 以列表形式返回哈希表的域和域的值
-
hGetAll
public <K,V> Map<K,CacheResult<V>> hGetAll(@NonNull CacheHashKey key, Function<CacheHashKey, Map<K, V>> loader, boolean... cacheNullValues) Description copied from interface:CachePlusOps返回哈希表 key 中,所有的域和值。 在返回值里,紧跟每个域名(field name)之后是域的值(value),所以返回值的长度是哈希表大小的两倍。- Specified by:
hGetAllin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.loader- 加载回调cacheNullValues- 缓存空值- Returns:
- 以列表形式返回哈希表的域和域的值
-
sAdd
Description copied from interface:CachePlusOps将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略。 假如 key 不存在,则创建一个只包含 member 元素作成员的集合。 当 key 不是集合类型时,返回一个错误。- Specified by:
sAddin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.value- 值- Returns:
- 被添加到集合中的新元素的数量,不包括被忽略的元素。
-
sRem
Description copied from interface:CachePlusOps移除集合 key 中的一个或多个 member 元素,不存在的 member 元素会被忽略。 当 key 不是集合类型,返回一个错误。- Specified by:
sRemin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.members- 元素- Returns:
- 被成功移除的元素的数量,不包括被忽略的元素
-
sMembers
Description copied from interface:CachePlusOps返回集合 key 中的所有成员。 不存在的 key 被视为空集合。- Specified by:
sMembersin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.- Returns:
- 集合中的所有成员。
-
sPop
Description copied from interface:CachePlusOps移除并返回集合中的一个随机元素。 如果只想获取一个随机元素,但不想该元素从集合中被移除的话,可以使用 SRANDMEMBER 命令。- Specified by:
sPopin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.- Returns:
- 被移除的随机元素。 当 key 不存在或 key 是空集时,返回 nil 。
-
sCard
Description copied from interface:CachePlusOps返回集合 key 的基数(集合中元素的数量)。- Specified by:
sCardin interfaceCachePlusOps- Parameters:
key- 一定不能为 null.- Returns:
- 集合的基数。 当 key 不存在时,返回 0 。
-