• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

RedisTemplate.ophotoshopForValue的常用方法

武飞扬头像
hippoDocker
帮助1

RedisTemplate.opsForValue常用方法

  1. 简介
    项目一般都会有缓存,常常使用redis来存取缓存(现在已不推荐使用session存储缓存),我们的键(key)和值(value)都是通过Spring提供的Serializer序列化到数据库的。RedisTemplate默认使用的是JdkSerializationRedisSerializer,StringRedisTemplate默认使用的是StringRedisSerializer。
  2. RedisTemplate.opsForValue常用方法
 //新增一个字符串类型的值,key是键,value是值
set(K key, V value)
redisTemplate.opsForValue().set("stringValue","bbb");

//获取key键对应的值
get(Object key)
redisTemplate.opsForValue().get("stringValue");

//在原有的值基础上新增字符串到末尾
append(K key, String value)
redisTemplate.opsForValue().append("stringValue","aaa");

//截取key键对应值得字符串,从开始下标位置开始到结束下标的位置(包含结束下标)的字符串
get(K key, long start, long end)
redisTemplate.opsForValue().get("stringValue",0,3);

//获取原来key键对应的值并重新赋新值
getAndSet(K key, V value)
String oldValue = redisTemplate.opsForValue().getAndSet("stringValue","ccc");

//key键对应的值value对应的ascll码,在offset的位置(从左向右数)变为ascll码的value
setBit(K key, long offset, boolean value)
redisTemplate.opsForValue().setBit("stringValue",1,false);

//判断指定的位置ASCII码的bit位是否为1
getBit(K key, long offset)
boolean bitBoolean = redisTemplate.opsForValue().getBit("stringValue",1);

//获取指定字符串的长度
size(K key)
Long stringValueLength = redisTemplate.opsForValue().size("stringValue");

//以增量的方式将long值存储在变量中
increment(K key, long delta)
double stringValueLong = redisTemplate.opsForValue().increment("longValue",6);

//如果键不存在则新增,存在则不改变已经有的值
setIfAbsent(K key, V value)
boolean absentBoolean = redisTemplate.opsForValue().setIfAbsent("absentValue","fff");

//设置变量值的过期时间
set(K key, V value, long timeout, TimeUnit unit)
redisTemplate.opsForValue().set("timeOutValue","timeOut",5,TimeUnit.SECONDS);

//覆盖从指定位置开始的值
set(K key, V value, long offset)
redisTemplate.opsForValue().set("absentValue","dd",1);

//设置map集合到redis
multiSet(Map<? extends K,? extends V> map)
Map valueMap = new HashMap(){{//匿名内部内
        put("valueMap1","map1");
        put("valueMap2","map2");
        put("valueMap3","map3");
}};
redisTemplate.opsForValue().multiSet(valueMap);

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgcgkfj
系列文章
更多 icon
同类精品
更多 icon
继续加载