|
| 1 | +package com.ipman.springboot.redis.jedis.sample.api; |
| 2 | + |
| 3 | +import com.ipman.springboot.redis.jedis.sample.utils.JedisUtil; |
| 4 | +import org.springframework.beans.factory.annotation.Autowired; |
| 5 | +import org.springframework.web.bind.annotation.GetMapping; |
| 6 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 7 | +import org.springframework.web.bind.annotation.RequestParam; |
| 8 | +import org.springframework.web.bind.annotation.RestController; |
| 9 | + |
| 10 | +/** |
| 11 | + * Created by ipipman on 2021/1/20. |
| 12 | + * |
| 13 | + * @version V1.0 |
| 14 | + * @Package com.ipman.springboot.redis.jedis.sample.api |
| 15 | + * @Description: (用一句话描述该文件做什么) |
| 16 | + * @date 2021/1/20 8:46 下午 |
| 17 | + */ |
| 18 | +@RestController |
| 19 | +@RequestMapping("/jedis") |
| 20 | +public class JedisController { |
| 21 | + |
| 22 | + @Autowired |
| 23 | + JedisUtil jedisUtil; |
| 24 | + |
| 25 | + /** |
| 26 | + * 使用Jedis工具类,调用Redis的Set指令 |
| 27 | + * http://127.0.0.1:8080/lettuce/set?key=name&val=ipipman |
| 28 | + * |
| 29 | + * @param key |
| 30 | + * @param val |
| 31 | + * @return |
| 32 | + */ |
| 33 | + @GetMapping("/set") |
| 34 | + public Object setItem(@RequestParam(name = "key", required = true) String key, |
| 35 | + @RequestParam(name = "val", required = true) String val) { |
| 36 | + return jedisUtil.set(key, val, 0); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * 使用Jedis工具类,调用Redis的Get指令 |
| 41 | + * http://127.0.0.1:8080/lettuce/get?key=name |
| 42 | + * |
| 43 | + * @param key |
| 44 | + * @return |
| 45 | + */ |
| 46 | + @GetMapping("/get") |
| 47 | + public Object getItem(@RequestParam(name = "key", required = true) String key) { |
| 48 | + return jedisUtil.get(key, 0); |
| 49 | + } |
| 50 | +} |
0 commit comments