springboot+redis基本使用

  1. 导入maven坐标

    <!-- 配置使用redis启动器 -->
    <dependency>
    	<groupId>org.springframework.boot</groupId>
    	<artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>
    
  2. application.properties配置信息

    ###REDIS (RedisProperties) redis�������ã�
    ########################################################
    # database name
    spring.redis.database=0
    # server host1
    spring.redis.host=127.0.0.1
    # server password
    #spring.redis.password=
    #connection port
    spring.redis.port=6379
    # pool settings ...
    spring.redis.jedis.pool.max-idle=8
    spring.redis.jedis.pool.min-idle=0
    spring.redis.jedis.pool.max-active=8
    
  3. Redis中存取值操作

    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    //存值
    redisTemplate.opsForValue().set("120", "2354", 24,TimeUnit.HOURS);
    //取值
    redisTemplate.opsForValue().get("120");
    

猜你喜欢

转载自blog.csdn.net/qq_42917455/article/details/84197390
今日推荐