zoukankan      html  css  js  c++  java
  • SpringBoot项目中,Redis的初次使用

    1.引入Redis依赖包,在application.yml中配置redis

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
            </dependency>
    Spring:
      redis:
        host: 192.168.1.105
        port: 6379
        password: 

    2.引入Redis模板,这里我只使用了,StringRedisTemplate

        @Autowired
        private StringRedisTemplate redisTemplate;

    3.数据存入Redis中

            String token = UUID.randomUUID().toString();
            Integer expire = RedisConstant.EXPORE;
            redisTemplate.opsForValue().set(String.format(RedisConstant.TOKEN_PREFIX, token), openid, expire, TimeUnit.SECONDS);
    redisTemplate.opsForValue().set()方法中
    第一个参数:存放的数据的名称String.format(RedisConstant.TOKEN_PREFIX, token)
    第二个参数:存放的内容:openid
    第三个参数:存放的时间:expire
    第四个参数:存放的格式:TimeUnit.SECONDS

    4.在Redis中查询内容

    5.注销Redis中内容

    redisTemplate.opsForValue().getOperations().delete((String.format(RedisConstant.TOKEN_PREFIX, cookie.getValue())));
    redisTemplate.opsForValue().getOperations().delete()
    第一个参数:注销的内容的名称(String.format(RedisConstant.TOKEN_PREFIX, cookie.getValue()))

    借用了redis的桌面可视化工具方便查看数据






  • 相关阅读:
    tomcat部署https
    Java程序内存的简单分析
    接口设计原则
    英语常用口语
    洛谷 P3956 棋盘
    洛谷 P1101 单词方阵
    二分查找模板(准确找定值)
    洛谷 P1892 [BOI2003]团伙
    浅谈二分的边界问题
    deque简单解析
  • 原文地址:https://www.cnblogs.com/xzmxddx/p/10329718.html
Copyright © 2011-2022 走看看