首页IT科技string的replace函数(【StringRedisTemplate常见用法】)

string的replace函数(【StringRedisTemplate常见用法】)

时间2025-09-19 01:05:19分类IT科技浏览5068
导读:文章目录...

文章目录

目录

一                、StringRedisTemplate是什么?

二                         、使用方法

1.构造方法

2.常用操作方法 

2.1从RedisTemplate继承的方法

2.2从RedisAccessor继承的方法

2.3从Object继承的方法

2.4从RedisOperations继承的方法

3.常见使用方法 

一         、StringRedisTemplate是什么?

StringRedisTemplate继承自RedisTemplate类                ,实现了BeanClassLoaderAware                         ,Aware         ,InitializingBean            ,RedisOperations<K, V>接口                 。StringRedisTemplate是RedisTemplate以字符串为中心的扩展                        ,由于针对 Redis 的大多数操作都是基于字符串的             ,因此此类提供了一个专用类                         。StringRedisTemplate是默认采用的是String的序列化策略        ,保存的key和value都是采用此策略序列化保存的        。

二            、使用方法

1.构造方法

StringRedisTemplate提供了两个构造方法:

方法 描述 StringRedisTemplate() 构造一个新StringRedisTemplate实例            。 StringRedisTemplate(RedisConnectionFactory connectionFactory) 构造一个StringRedisTemplate可以使用的新实例                         。

2.常用操作方法 

2.1从RedisTemplate继承的方法(方法实在太多                        ,感兴趣的可以去官网了解下)

 ​​​​​​afterPropertiesSet, boundGeoOps, boundHashOps, boundListOps, boundSetOps, boundStreamOps, boundValueOps, boundZSetOps, convertAndSend, copy, countExistingKeys, createRedisConnectionProxy, delete, delete, discard, dump, exec, exec, execRaw, execute, execute, execute, execute, execute, execute, executePipelined, executePipelined, executePipelined, executePipelined, executeWithStickyConnection, expire, expireAt, getClientList, getDefaultSerializer, getExpire, getExpire, getHashKeySerializer, getHashValueSerializer, getKeySerializer, getStringSerializer, getValueSerializer, hasKey, isEnableDefaultSerializer, isExposeConnection, keys, killClient, move, multi, opsForCluster, opsForGeo, opsForHash, opsForHyperLogLog, opsForList, opsForSet, opsForStream, opsForStream, opsForValue, opsForZSet, persist, postProcessResult, randomKey, rename, renameIfAbsent, restore, scan, setBeanClassLoader, setDefaultSerializer, setEnableDefaultSerializer, setEnableTransactionSupport, setExposeConnection, setHashKeySerializer, setHashValueSerializer, setKeySerializer, setScriptExecutor, setStringSerializer, setValueSerializer, slaveOf, slaveOfNoOne, sort, sort, sort, sort, sort, type, unlink, unlink, unwatch, watch, watch

2.2从RedisAccessor继承的方法

方法 描述 getConnectionFactory() 返回连接工厂            。 getRequiredConnectionFactory() 如果未设置连接工厂                 ,则返回必需的RedisConnectionFactory或抛出IllegalStateException setConnectionFactory(RedisConnectionFactory connectionFactory) 设置连接工厂        。

2.3从Object继承的方法

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

2.4从RedisOperations继承的方法

返回类型 方法 描述 default Boolean expire(K key, Duration timeout) 为给定的生活设定时间key                         。 Boolean expire(K key, long timeout, TimeUnit unit) 为给定的生活设定时间key                。 Boolean expireAt(K key, Date date) 将给定的到期时间设置key为日期时间戳    。 default Boolean expireAt(K key, Instant expireAt) 将给定的到期时间设置key为日期时间戳                         。 default void restore(K key, byte[] value, long timeToLive, TimeUnit unit) 创建key使用serializedValue    ,之前获得使用dump(Object)                    。 void restore(K key, byte[] value, long timeToLive, TimeUnit unit, boolean replace) 创建key使用serializedValue                        ,之前获得使用dump(Object)。

3.常见使用方法 

//检查key是否存在                     ,返回boolean值

1.stringRedisTemplate.hasKey(String key)

//根据key获取缓存中value

2.stringRedisTemplate.opsForValue().get(Object key)

//截取key键对应缓存中的字符串,从开始下标位置开始到结束下标的位置(包含结束下标)

3.stringRedisTemplate.opsForValue().get(String key,long start,long end)

//向缓存中存入key值对应的value数据

4.stringRedisTemplate.opsForValue().set(String key,String value)

//覆盖从指定位置开始的值

5.stringRedisTemplate.opsForValue().set(String key,String value,long offset)

//向缓存中存入数据                    ,并指定过期时间

6.stringRedisTemplate.opsForValue().set(String key,String value,Duration timeout)

//向缓存中存入数据                         ,并指定过期时间

7.stringRedisTemplate.opsForValue().set(String key,String value,long timeout,TimeUnit unit)

//向缓存中存入数据    ,以map形式存储

8.stringRedisTemplate.opsForHash().putAll(String key,Map<?,?> m);

//向缓存中存入数据

9.stringRedisTemplate.opsForHash().put(String key,Object hashkey,Object value);

//删除缓存

10.stringRedisTemplate.delete(String key,Object ...hashkeys);

//以增量形式存储

11.stringRedisTemplate.opsForValue().increment(String key);

//以增量的方式将long值存储在变量中,相当于一个计数器(计算 +)

12.stringRedisTemplate.opsForValue().increment(String key,long delta);

//以增量的方式将double值存储在变量中,相当于一个计数器(计算 +)

13.stringRedisTemplate.opsForValue().increment(String key,double delta);

//获取key对应的map

14.stringRedisTemplate.opsForHash().entries(String key)

//设置过期时间

15.stringRedisTemplate.expire(String key,Duration timeout)

16.stringRedisTemplate.expire(String key,long timeout,TimeUnit unit)

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
逆波兰表达式运算符优先级(用Python举例实现逆波兰表达式) 打字赚钱平台软件下载(打字赚钱最多的是什么平台-手机打字**真的靠谱吗?)