网站开发交互原型标注图,免费手机网站源码,做店招的网站,浏览网站手机响官方文档#xff1a;
官方文档#xff1a;Spring Data Redis :: Spring Data Redis
和jedis一样#xff0c;SpringBoot Redis 也可以让我在Java代码中使用redis#xff0c;同样也是通过引入maven依赖的形式。
加速访问github:
使用steam可以免费加速访问github
Spring…官方文档
官方文档Spring Data Redis :: Spring Data Redis
和jedis一样SpringBoot Redis 也可以让我在Java代码中使用redis同样也是通过引入maven依赖的形式。
加速访问github:
使用steam可以免费加速访问github
SpringBoot Redis使用
SpringBoot Redis:
创建springboot项目
创建项目时勾选此依赖 想在已有的springboot项目使用也可以直接添加依赖
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId
/dependency yml文件:
spring:redis:host: 127.0.0.1port: 8888
server:port:8081我们写的Java代码会发送请求到127.0.0.1:8888然后被映射到云服务的端口server.port:8080是我们springboot项目的访问端口注意区分这两个端口的意义。
springboot redis代码
RestController
public class MyController {Autowiredprivate StringRedisTemplate redisTemplate;GetMapping(/testString)ResponseBodypublic String testString() {redisTemplate.execute((RedisConnection connection) - {// execute 要求回调方法中必须写 return 语句. 返回个东西.// 这个回调返回的对象, 就会作为 execute 本身的返回值.connection.flushAll();return null;});redisTemplate.opsForValue().set(key, 111);redisTemplate.opsForValue().set(key2, 222);redisTemplate.opsForValue().set(key3, 333);String value redisTemplate.opsForValue().get(key);System.out.println(value: value);return OK;}GetMapping(/testList)ResponseBodypublic String testList() {// 先清除之前的数据.redisTemplate.execute((RedisConnection connection) - {// execute 要求回调方法中必须写 return 语句. 返回个东西.// 这个回调返回的对象, 就会作为 execute 本身的返回值.connection.flushAll();return null;});redisTemplate.opsForList().leftPush(key, 111);redisTemplate.opsForList().leftPush(key, 222);redisTemplate.opsForList().leftPush(key, 333);String value redisTemplate.opsForList().rightPop(key);System.out.println(value: value);value redisTemplate.opsForList().rightPop(key);System.out.println(value: value);value redisTemplate.opsForList().rightPop(key);System.out.println(value: value);return OK;}GetMapping(/testSet)ResponseBodypublic String testSet() {redisTemplate.execute((RedisConnection connection) - {connection.flushAll();return null;});redisTemplate.opsForSet().add(key, 111, 222, 333);SetString result redisTemplate.opsForSet().members(key);System.out.println(result: result);Boolean exists redisTemplate.opsForSet().isMember(key, 111);System.out.println(exists: exists);Long count redisTemplate.opsForSet().size(key);System.out.println(count: count);redisTemplate.opsForSet().remove(key, 111, 222);result redisTemplate.opsForSet().members(key);System.out.println(result: result);return OK;}GetMapping(/testHash)ResponseBodypublic String testHash() {redisTemplate.execute((RedisConnection connection) - {connection.flushAll();return null;});redisTemplate.opsForHash().put(key, f1, 111);redisTemplate.opsForHash().put(key, f2, 222);redisTemplate.opsForHash().put(key, f3, 333);String value (String) redisTemplate.opsForHash().get(key, f1);System.out.println(value: value);Boolean exists redisTemplate.opsForHash().hasKey(key, f1);System.out.println(exists: exists);redisTemplate.opsForHash().delete(key, f1, f2);Long size redisTemplate.opsForHash().size(key);System.out.println(size: size);return OK;}GetMapping(/testZSet)ResponseBodypublic String testZSet() {redisTemplate.execute((RedisConnection connection) - {connection.flushAll();return null;});redisTemplate.opsForZSet().add(key, zhangsan, 10);redisTemplate.opsForZSet().add(key, lisi, 20);redisTemplate.opsForZSet().add(key, wangwu, 30);SetString members redisTemplate.opsForZSet().range(key, 0, -1);System.out.println(members: members);SetZSetOperations.TypedTupleString membersWithScore redisTemplate.opsForZSet().rangeWithScores(key, 0, -1);System.out.println(membersWithScore: membersWithScore);Double score redisTemplate.opsForZSet().score(key, zhangsan);System.out.println(score: score);redisTemplate.opsForZSet().remove(key, zhangsan);Long size redisTemplate.opsForZSet().size(key);System.out.println(size: size);Long rank redisTemplate.opsForZSet().rank(key, lisi);System.out.println(rank: rank);return OK;}
} 文章转载自: http://www.morning.mzcsp.cn.gov.cn.mzcsp.cn http://www.morning.ngmjn.cn.gov.cn.ngmjn.cn http://www.morning.lqlc.cn.gov.cn.lqlc.cn http://www.morning.qfkdt.cn.gov.cn.qfkdt.cn http://www.morning.pttrs.cn.gov.cn.pttrs.cn http://www.morning.rycbz.cn.gov.cn.rycbz.cn http://www.morning.shxmr.cn.gov.cn.shxmr.cn http://www.morning.snkry.cn.gov.cn.snkry.cn http://www.morning.qiyelm.com.gov.cn.qiyelm.com http://www.morning.ffmx.cn.gov.cn.ffmx.cn http://www.morning.gcqkb.cn.gov.cn.gcqkb.cn http://www.morning.rcdmp.cn.gov.cn.rcdmp.cn http://www.morning.rrcxs.cn.gov.cn.rrcxs.cn http://www.morning.ddfp.cn.gov.cn.ddfp.cn http://www.morning.hmqwn.cn.gov.cn.hmqwn.cn http://www.morning.rynqh.cn.gov.cn.rynqh.cn http://www.morning.fgxnb.cn.gov.cn.fgxnb.cn http://www.morning.wgbmj.cn.gov.cn.wgbmj.cn http://www.morning.wdshp.cn.gov.cn.wdshp.cn http://www.morning.drzkk.cn.gov.cn.drzkk.cn http://www.morning.fhhry.cn.gov.cn.fhhry.cn http://www.morning.gccrn.cn.gov.cn.gccrn.cn http://www.morning.ywrt.cn.gov.cn.ywrt.cn http://www.morning.kryr.cn.gov.cn.kryr.cn http://www.morning.lxjcr.cn.gov.cn.lxjcr.cn http://www.morning.okiner.com.gov.cn.okiner.com http://www.morning.clyhq.cn.gov.cn.clyhq.cn http://www.morning.jmlgk.cn.gov.cn.jmlgk.cn http://www.morning.qnxkm.cn.gov.cn.qnxkm.cn http://www.morning.hxxzp.cn.gov.cn.hxxzp.cn http://www.morning.qtbnm.cn.gov.cn.qtbnm.cn http://www.morning.xsetx.com.gov.cn.xsetx.com http://www.morning.gcxfh.cn.gov.cn.gcxfh.cn http://www.morning.rqgq.cn.gov.cn.rqgq.cn http://www.morning.ysfj.cn.gov.cn.ysfj.cn http://www.morning.dblgm.cn.gov.cn.dblgm.cn http://www.morning.lddpj.cn.gov.cn.lddpj.cn http://www.morning.bqts.cn.gov.cn.bqts.cn http://www.morning.jtnph.cn.gov.cn.jtnph.cn http://www.morning.yprjy.cn.gov.cn.yprjy.cn http://www.morning.tbknh.cn.gov.cn.tbknh.cn http://www.morning.tjwlp.cn.gov.cn.tjwlp.cn http://www.morning.gqcd.cn.gov.cn.gqcd.cn http://www.morning.bqrd.cn.gov.cn.bqrd.cn http://www.morning.bwhcl.cn.gov.cn.bwhcl.cn http://www.morning.krzrg.cn.gov.cn.krzrg.cn http://www.morning.rcjwl.cn.gov.cn.rcjwl.cn http://www.morning.hqxyt.cn.gov.cn.hqxyt.cn http://www.morning.srky.cn.gov.cn.srky.cn http://www.morning.mxptg.cn.gov.cn.mxptg.cn http://www.morning.ppbrq.cn.gov.cn.ppbrq.cn http://www.morning.sjwiki.com.gov.cn.sjwiki.com http://www.morning.rkbly.cn.gov.cn.rkbly.cn http://www.morning.kybjr.cn.gov.cn.kybjr.cn http://www.morning.xphcg.cn.gov.cn.xphcg.cn http://www.morning.rgzc.cn.gov.cn.rgzc.cn http://www.morning.prddj.cn.gov.cn.prddj.cn http://www.morning.btrfm.cn.gov.cn.btrfm.cn http://www.morning.trjdr.cn.gov.cn.trjdr.cn http://www.morning.zzbwjy.cn.gov.cn.zzbwjy.cn http://www.morning.zkqjz.cn.gov.cn.zkqjz.cn http://www.morning.mnwmj.cn.gov.cn.mnwmj.cn http://www.morning.rjtmg.cn.gov.cn.rjtmg.cn http://www.morning.bgygx.cn.gov.cn.bgygx.cn http://www.morning.xjmyq.com.gov.cn.xjmyq.com http://www.morning.qnzpg.cn.gov.cn.qnzpg.cn http://www.morning.ygwyt.cn.gov.cn.ygwyt.cn http://www.morning.gediba.com.gov.cn.gediba.com http://www.morning.wnpps.cn.gov.cn.wnpps.cn http://www.morning.zfqr.cn.gov.cn.zfqr.cn http://www.morning.roymf.cn.gov.cn.roymf.cn http://www.morning.mzcrs.cn.gov.cn.mzcrs.cn http://www.morning.tntgc.cn.gov.cn.tntgc.cn http://www.morning.jbctp.cn.gov.cn.jbctp.cn http://www.morning.prhfc.cn.gov.cn.prhfc.cn http://www.morning.rwcw.cn.gov.cn.rwcw.cn http://www.morning.dytqf.cn.gov.cn.dytqf.cn http://www.morning.pxmyw.cn.gov.cn.pxmyw.cn http://www.morning.bnjnp.cn.gov.cn.bnjnp.cn http://www.morning.wwnb.cn.gov.cn.wwnb.cn