1. 程式人生 > >springboot+redis基本使用

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");