1 Star 0 Fork 217

乘风之翼 / redisson-spring-boot-starter

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
object.md 1.40 KB
Copy Edit Raw Blame History
zengtengpeng authored 2019-04-01 16:13 . 增加元素存储模板

@Controller
public class ObjectController {

    @Resource
    private RedissonObject redissonObject;

    /**
     * 设置值
     * @param user
     * @param request
     * @param response
     * @return
     * @throws InterruptedException
     */
    @RequestMapping("/object1")
    @ResponseBody
    public String object1(User user, HttpServletRequest request, HttpServletResponse response) throws InterruptedException {
        User user1 = new User();
        user1.setName("test");
        user1.setAge("123");
        redissonObject.setValue("object1", user1,-1L);
        return "";
    }

    /**
     * 获取值
     * @param user
     * @param request
     * @param response
     * @return
     * @throws InterruptedException
     */
    @RequestMapping("/object2")
    @ResponseBody
    public Object object2(User user, HttpServletRequest request, HttpServletResponse response) throws InterruptedException {
        return redissonObject.getValue("object1");
    }

    /**
     * 如果对象不存在则设置,否则不设置
     * @param user
     * @param request
     * @param response
     * @return
     * @throws InterruptedException
     */
    @RequestMapping("/object3")
    @ResponseBody
    public String object3(User user, HttpServletRequest request, HttpServletResponse response) throws InterruptedException {
        return redissonObject.trySetValue("object1","object1-2")+"";
    }
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/windfly027/redisson-spring-boot-starter.git
git@gitee.com:windfly027/redisson-spring-boot-starter.git
windfly027
redisson-spring-boot-starter
redisson-spring-boot-starter
master

Search

344bd9b3 5694891 D2dac590 5694891