Spring Data Redis-操作String类型数据
Spring Data Redis-操作String类型数据
@SpringBootTest
@RunWith(SpringRunner.class)
class SpringdataredisDemoApplicationTests {
@Autowired
private RedisTemplate redisTemplate;
/**
* 操作String类型数据
*/
@Test
public void testString() {
redisTemplate.opsForValue().set("city123", "beijing");
String value = (String) redisTemplate.opsForValue().get("city123");
System.out.println(value);
redisTemplate.opsForValue().set("key1", "value1", 10l, TimeUnit.SECONDS);
Boolean aBoolean = redisTemplate.opsForValue().setIfAbsent("city1234","name");
System.out.println(aBoolean);
}
}