/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.el.utils;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.*;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* @author /
*/
@Component
@SuppressWarnings({"unchecked", "all"})
public class RedisUtils {
private static final Logger log = LoggerFactory.getLogger(RedisUtils.class);
private RedisTemplate<Object, Object> redisTemplate;
@Value("${jwt.online-key}")
private String onlineKey;
public RedisUtils(RedisTemplate<Object, Object> redisTemplate) {
this.redisTemplate = redisTemplate;
}
/**
* 指定缓存失效时间
*
* @param key 键
* @param time 时间(秒)
*/
public boolean expire(String key, long time) {
try {
if (time > 0) {
redisTemplate.expire(key, time, TimeUnit.SECONDS);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
return true;
}
/**
* 指定缓存失效时间
*
* @param key 键
* @param time 时间(秒)
* @param timeUnit 单位
*/
public boolean expire(String key, long time, TimeUnit timeUnit) {
try {
if (time > 0) {
redisTemplate.expire(key, time, timeUnit);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
return true;
}
/**
* 根据 key 获取过期时间
*
* @param key 键 不能为null
* @return 时间(秒) 返回0代表为永久有效
*/
public long getExpire(Object key) {
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
}
/**
* 查找匹配key
*
* @param pattern key
* @return /
*/
public List<String> scan(String pattern) {
ScanOptions options = ScanOptions.scanOptions().match(pattern).build();
RedisConnectionFactory factory = redisTemplate.getConnectionFactory();
RedisConnection rc = Objects.requireNonNull(factory).getConnection();
Cursor<byte[]> cursor = rc.scan(options);
List<String> result = new ArrayList<>();
while (cursor.hasNext()) {
result.add(new String(cursor.next()));
}
try {
RedisConnectionUtils.releaseConnection(rc, factory);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return result;
}
/**
* 分页查询 key
*
* @param patternKey key
* @param page 页码
* @param size 每页数目
* @return /
*/
public List<String> findKeysForPage(String patternKey, int page, int size) {
ScanOptions options = ScanOptions.scanOptions().match(patternKey).build();
RedisConnectionFactory factory = redisTemplate.getConnectionFactory();
RedisConnection rc = Objects.requireNonNull(factory).getConnection();
Cursor<byte[]> cursor = rc.scan(options);
List<String> result = new ArrayList<>(size);
int tmpIndex = 0;
int fromIndex = page * size;
int toIndex = page * size + size;
while (cursor.hasNext()) {
if (tmpIndex >= fromIndex && tmpIndex < toIndex) {
result.add(new String(cursor.next()));
tmpIndex++;
continue;
}
// 获取到满足条件的数据后,就可以退出了
if (tmpIndex >= toIndex) {
break;
}
tmpIndex++;
cursor.next();
}
try {
RedisConnectionUtils.releaseConnection(rc, factory);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return result;
}
/**
* 判断key是否存在
*
* @param key 键
* @return true 存在 false不存在
*/
public boolean hasKey(String key) {
try {
return redisTemplate.hasKey(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 删除缓存
*
* @param key 可以传一个值 或多个
*/
public void del(String... keys) {
if (keys != null && keys.length > 0) {
if (keys.length == 1) {
boolean result = redisTemplate.delete(keys[0]);
log.debug("--------------------------------------------");
log.debug(new StringBuilder("删除缓存:").append(keys[0]).append(",结果:").append(result).toString());
log.debug("--------------------------------------------");
} else {
Set<Object> keySet = new HashSet<>();
for (String key : keys) {
keySet.addAll(redisTemplate.keys(key));
}
long count = redisTemplate.delete(keySet);
log.debug("--------------------------------------------");
log.debug("成功删除缓存:" + keySet.toString());
log.debug("缓存删除数量:" + count + "个");
log.debug("--------------------------------------------");
}
}
}
// ============================String=============================
/**
* 普通缓存获取
*
* @param key 键
* @return 值
*/
public Object get(String key) {
return key == null ? null : redisTemplate.opsForValue().get(key);
}
/**
* 批量获取
*
* @param keys
* @return
*/
public List<Object> multiGet(List<String> keys) {
List list = redisTemplate.opsForValue().multiGet(Sets.newHashSet(keys));
List resultList = Lists.newArrayList();
Optional.ofNullable(list).ifPresent(e-> list.forEach(ele-> Optional.ofNullable(ele).ifPresent(resultList::add)));
return resultList;
}
/**
* 普通缓存放入
*
* @param key 键
* @param value 值
* @return true成功 false失败
*/
public boolean set(String key, Object value) {
try {
redisTemplate.opsForValue().set(key, value);
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 普通缓存放入并设置时间
*
* @param key 键
* @param value 值
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
* @return true成功 false 失败
*/
public boolean set(String key, Object value, long time) {
try {
if (time > 0) {
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
} else {
set(key, value);
}
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
/**
* 普通缓存放入并设置�
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot+Vuejs+element-ui的新闻发布管理系统源码+项目说明.zip
共1208个文件
class:371个
java:346个
vue:124个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 29 浏览量
2022-12-29
16:45:01
上传
评论 2
收藏 3.2MB ZIP 举报
温馨提示
基于SpringBoot+Vuejs+element-ui的新闻发布管理系统源码+项目说明.zip 项目简介 一个基于 Spring Boot 、 Spring Boot Jpa、 JWT、Spring Security、Redis、Vue、eladmin的新闻发布管理系统 初始账号密码: admin / 123456 系统功能 用户管理:提供用户的相关配置,新增用户后,默认密码为123456 角色管理:对权限与菜单进行分配,可根据部门设置角色的数据权限 菜单管理:已实现菜单动态路由,后端可配置化,支持多级菜单 部门管理:可配置系统组织架构,树形表格展示 岗位管理:配置各个部门的职位 字典管理:可维护常用一些固定的数据,如:状态,性别等 系统日志:记录用户操作日志与异常日志,方便开发人员定位排错 SQL监控:采用druid 监控数据库访问性能,默认用户名admin,密码123456 定时任务:整合Quartz做定时任务,加入任务日志,任务运行情况一目了然 代码生成:高灵活度生成前后端代码,减少大量重复的工作任务 邮件工具:配合富文本,发送html格式的邮件 七牛云存储:可同步七牛云存储
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot+Vuejs+element-ui的新闻发布管理系统源码+项目说明.zip (1208个子文件)
MenuServiceImpl.class 21KB
DeployServiceImpl.class 20KB
RedisUtils.class 18KB
RoleServiceImpl.class 17KB
DeptServiceImpl.class 17KB
UserServiceImpl.class 16KB
QiNiuServiceImpl.class 14KB
GenUtil.class 14KB
QuartzJobServiceImpl.class 13KB
LogServiceImpl.class 13KB
UserController.class 12KB
SpringSecurityConfig.class 12KB
GeneratorServiceImpl.class 11KB
NewsArticleServiceImpl.class 11KB
FileUtil.class 11KB
LocalStorageServiceImpl.class 11KB
JobServiceImpl.class 10KB
ServerDeployServiceImpl.class 10KB
DictServiceImpl.class 10KB
QueryHelp.class 10KB
AppServiceImpl.class 9KB
DatabaseServiceImpl.class 9KB
NewsCategoryServiceImpl.class 9KB
MenuController.class 9KB
UserMapperImpl.class 9KB
NewsCommentServiceImpl.class 9KB
AuthorizationController.class 9KB
NewsLinkServiceImpl.class 9KB
NewsTagServiceImpl.class 9KB
NewsArticleTagServiceImpl.class 9KB
DeployHistoryServiceImpl.class 9KB
OnlineUserService.class 9KB
RoleController.class 9KB
StringUtils.class 8KB
MonitorServiceImpl.class 8KB
NewsArticle.class 8KB
DeployController.class 8KB
DictDetailServiceImpl.class 8KB
NewsArticleDto.class 8KB
UserDetailsServiceImpl.class 8KB
SqlUtils.class 7KB
ExecutionJob.class 7KB
AlipayConfig.class 7KB
AliPayController.class 7KB
DatabaseController.class 7KB
QuartzLog.class 7KB
QiniuController.class 7KB
DeptController.class 7KB
User.class 7KB
DictMapperImpl.class 6KB
RoleMapperImpl.class 6KB
RsaUtils.class 6KB
NewsCategory.class 6KB
RedisConfig.class 6KB
GeneratorController.class 6KB
QuartzJobController.class 6KB
GlobalExceptionHandler.class 6KB
TokenProvider.class 6KB
Menu.class 6KB
NewsComment.class 6KB
NewsLink.class 6KB
NewsTag.class 6KB
MenuVo.class 6KB
QuartzManage.class 6KB
DataTypeEnum.class 6KB
QiniuContent.class 6KB
DeployMapperImpl.class 6KB
DictDetailController.class 5KB
LocalStorageController.class 5KB
LogErrorDTO.class 5KB
ConfigurerAdapter.class 5KB
EmailServiceImpl.class 5KB
AliPayServiceImpl.class 5KB
TradeVo.class 5KB
OnlineUserDto.class 5KB
SecurityProperties.class 5KB
TokenFilter.class 5KB
SwaggerConfig.class 5KB
QiniuConfig.class 5KB
NewsCategoryDto.class 5KB
UserCacheManager.class 5KB
Role.class 5KB
DictController.class 5KB
UserQueryCriteria.class 5KB
NewsArticleController.class 5KB
LimitAspect.class 5KB
ColumnInfo.class 5KB
LoginProperties.class 5KB
NewsCategoryController.class 5KB
MenuDto.class 5KB
ServerDeployController.class 5KB
UserDto.class 5KB
JobController.class 5KB
WebSocketServer.class 5KB
NewsTagController.class 5KB
SpringContextHolder.class 5KB
NewsLinkDto.class 5KB
NewsCommentDto.class 5KB
NewsTagDto.class 5KB
QuartzJob.class 5KB
共 1208 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
资源评论
- 天真小艾2023-08-10总算找到了自己想要的资源,对自己的启发很大,感谢分享~
Make程序设计
- 粉丝: 5727
- 资源: 3570
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功