forked from sfms3.0/sfms3.0
5 changed files with 88 additions and 9 deletions
@ -1,4 +0,0 @@ |
|||||
/** |
|
||||
* 采用 Spring Data Redis 操作 Redis,底层使用 Redisson 作为客户端 |
|
||||
*/ |
|
||||
package com.win.framework.redis; |
|
@ -0,0 +1,57 @@ |
|||||
|
package com.win.module.system.controller.redis; |
||||
|
|
||||
|
import com.win.framework.common.pojo.CommonResult; |
||||
|
import com.win.framework.redis.util.RedisCache; |
||||
|
import com.win.framework.security.core.LoginUser; |
||||
|
import com.win.framework.security.core.util.SecurityFrameworkUtils; |
||||
|
import com.win.module.system.controller.redis.vo.RedisReqVo; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import javax.validation.Valid; |
||||
|
|
||||
|
import static com.win.framework.common.pojo.CommonResult.success; |
||||
|
|
||||
|
/** |
||||
|
* 个性化设置增加缓存 |
||||
|
* |
||||
|
* @author win |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("/system/redis") |
||||
|
public class RedisController { |
||||
|
|
||||
|
@Resource |
||||
|
private RedisCache redisCache; |
||||
|
|
||||
|
/** |
||||
|
* 加入缓存 |
||||
|
*/ |
||||
|
@PostMapping("/set") |
||||
|
public CommonResult<Boolean> setRedisHash(@Valid @RequestBody RedisReqVo reqVO) { |
||||
|
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); |
||||
|
redisCache.setCacheMapValue(reqVO.getKey(), String.valueOf(loginUser.getId()), reqVO.getValue()); |
||||
|
return success(Boolean.TRUE); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取缓存 |
||||
|
*/ |
||||
|
@GetMapping("/get") |
||||
|
public CommonResult<String> getRedisHash(@Valid @RequestBody RedisReqVo reqVO) { |
||||
|
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); |
||||
|
String result = redisCache.getCacheMapValue(reqVO.getKey(), String.valueOf(loginUser.getId())); |
||||
|
return success(result); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除缓存 |
||||
|
*/ |
||||
|
@DeleteMapping("/delete") |
||||
|
public CommonResult<Boolean> deleteRedisHash(@Valid @RequestBody RedisReqVo reqVO) { |
||||
|
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); |
||||
|
Boolean result = redisCache.deleteCacheMapValue(reqVO.getKey(), String.valueOf(loginUser.getId())); |
||||
|
return success(result); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
package com.win.module.system.controller.redis.vo; |
||||
|
|
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
import javax.validation.constraints.Pattern; |
||||
|
import javax.validation.constraints.Size; |
||||
|
|
||||
|
/** |
||||
|
* 个性化设置增加缓存接口 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class RedisReqVo { |
||||
|
|
||||
|
@Schema(description = "缓存键", requiredMode = Schema.RequiredMode.REQUIRED, example = "basic_itembasic") |
||||
|
@NotBlank(message = "缓存键不能为空") |
||||
|
@Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "缓存键账号由 数字、字母 组成") |
||||
|
@Size(min = 4, max = 30, message = "缓存键长度为 4-30 个字符") |
||||
|
private String key; |
||||
|
|
||||
|
@Schema(description = "缓存值", requiredMode = Schema.RequiredMode.REQUIRED, example = "个性化列表") |
||||
|
@NotBlank(message = "缓存值不能为空") |
||||
|
private String value; |
||||
|
|
||||
|
} |
Loading…
Reference in new issue