前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >RedisTemplate

RedisTemplate

原创
作者头像
快乐但榴莲
修改2019-09-05 18:07:56
7800
修改2019-09-05 18:07:56
举报
文章被收录于专栏:冯志远的专栏冯志远的专栏
代码语言:javascript
复制
package com.fzy.javastudy.java.day_0905;

import com.fzy.javastudy.spring.apimodel.Api;
import com.fzy.javastudy.spring.apimodel.ApiResponse;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/day_0905")
public class RedisTestController {

    @Resource
    private RedisTemplate<String, Integer> redisTemplate;

    @Resource
    private RedisTemplate<String, String> stringRedisTemplate;

    @GetMapping("test1")
    public ApiResponse test1() {
        redisTemplate.opsForValue().set("test1_key1", 12);
        int value = redisTemplate.opsForValue().get("test1_key1");
        System.out.println(value);
        return Api.ok(value);
    }

    @GetMapping("test2")
    public ApiResponse test2() {
        stringRedisTemplate.opsForValue().set("test2_key2", "hello", 10, TimeUnit.SECONDS);
        String value = stringRedisTemplate.opsForValue().get("test2_key2");
        System.out.println(value);
        return Api.ok(value);
    }
}

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档