beigin,use springboot,select name from IE;
if we want to set,as this:
Now,let us start。
application.properties:
server.port=8085
spring.application.name=redis-server
Controller:
package com.huizhi.demoredis2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Controller {
@Autowired
private StringRedisTemplate template;
@RequestMapping("/redis/get/{key}")
private String get(@PathVariable("key") String key){
return template.opsForValue().get(key);
}
@RequestMapping("/redis/set/{key}/{value}")
private Boolean set(@PathVariable("key") String key,@PathVariable("value") String value){
boolean flag = true;
try {
template.opsForValue().set(key,value);
} catch (Exception e) {
e.printStackTrace();
flag = false;
}
return flag;
}
}
Demoredis2Application:
package com.huizhi.demoredis2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Demoredis2Application {
public static void main(String[] args) {
SpringApplication.run(Demoredis2Application.class, args);
}
}
dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>