天天看點

Redis快速使用

1.導包(坐标)

<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>
        <!-- 配置使用redis啟動器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>           

2.使用

2.1存資料:

@Autowired
private RedisTemplate<String, String> redisTemplate;

public void run(){
    /*
      參數一: key
      參數二:value
      參數三:title
      參數四:時間類型
     */
    redisTemplate.opsForValue().set(customer.getTelephone(), activecode, 24,TimeUnit.HOURS);
}            

2.2取資料

String  getUUid = redisTemplate.opsForValue().get(telephone);