Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
JAVA小学生-王铁柱
eladmin
提交
2b931a58
E
eladmin
项目概览
JAVA小学生-王铁柱
/
eladmin
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
eladmin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2b931a58
编写于
6月 04, 2019
作者:
Z
zhengjie
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of gitee.com:elunez/eladmin
上级
7eba9641
083bbdc6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
19 addition
and
102 deletion
+19
-102
eladmin-common/src/main/java/me/zhengjie/redis/RedisConfig.java
...n-common/src/main/java/me/zhengjie/redis/RedisConfig.java
+1
-35
eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/impl/RedisServiceImpl.java
...engjie/modules/monitor/service/impl/RedisServiceImpl.java
+17
-50
eladmin-system/src/main/resources/config/application.yml
eladmin-system/src/main/resources/config/application.yml
+0
-10
pom.xml
pom.xml
+1
-7
未找到文件。
eladmin-common/src/main/java/me/zhengjie/redis/RedisConfig.java
浏览文件 @
2b931a58
...
...
@@ -35,40 +35,6 @@ import java.time.Duration;
@EnableConfigurationProperties
(
RedisProperties
.
class
)
public
class
RedisConfig
extends
CachingConfigurerSupport
{
@Value
(
"${spring.redis.host}"
)
private
String
host
;
@Value
(
"${spring.redis.port}"
)
private
int
port
;
@Value
(
"${spring.redis.timeout}"
)
private
int
timeout
;
@Value
(
"${spring.redis.jedis.pool.max-idle}"
)
private
int
maxIdle
;
@Value
(
"${spring.redis.jedis.pool.max-wait}"
)
private
long
maxWaitMillis
;
@Value
(
"${spring.redis.password}"
)
private
String
password
;
@Value
(
"${spring.redis.database}"
)
private
int
database
;
/**
* 配置 redis 连接池
* @return
*/
@Bean
public
JedisPool
redisPoolFactory
(){
JedisPoolConfig
jedisPoolConfig
=
new
JedisPoolConfig
();
jedisPoolConfig
.
setMaxIdle
(
maxIdle
);
jedisPoolConfig
.
setMaxWaitMillis
(
maxWaitMillis
);
String
pwd
=
StringUtils
.
isBlank
(
password
)
?
null
:
password
;
return
new
JedisPool
(
jedisPoolConfig
,
host
,
port
,
timeout
,
pwd
,
database
);
}
/**
* 设置 redis 数据默认过期时间,默认1天
* 设置@cacheable 序列化方式
...
...
@@ -126,4 +92,4 @@ public class RedisConfig extends CachingConfigurerSupport {
return
sb
.
toString
();
};
}
}
\ No newline at end of file
}
eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/impl/RedisServiceImpl.java
浏览文件 @
2b931a58
...
...
@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageImpl
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
redis.clients.jedis.Jedis
;
import
redis.clients.jedis.JedisPool
;
...
...
@@ -21,72 +22,38 @@ import java.util.List;
public
class
RedisServiceImpl
implements
RedisService
{
@Autowired
JedisPool
pool
;
RedisTemplate
redisTemplate
;
@Override
public
Page
findByKey
(
String
key
,
Pageable
pageable
){
Jedis
jedis
=
null
;
try
{
jedis
=
pool
.
getResource
();
List
<
RedisVo
>
redisVos
=
new
ArrayList
<>();
if
(!
key
.
equals
(
"*"
)){
key
=
"*"
+
key
+
"*"
;
}
for
(
String
s
:
jedis
.
keys
(
key
))
{
RedisVo
redisVo
=
new
RedisVo
(
s
,
jedis
.
get
(
s
));
redisVos
.
add
(
redisVo
);
}
Page
<
RedisVo
>
page
=
new
PageImpl
<
RedisVo
>(
PageUtil
.
toPage
(
pageable
.
getPageNumber
(),
pageable
.
getPageSize
(),
redisVos
),
pageable
,
redisVos
.
size
());
return
page
;
}
finally
{
if
(
null
!=
jedis
){
jedis
.
close
();
// 释放资源还给连接池
}
List
<
RedisVo
>
redisVos
=
new
ArrayList
<>();
if
(!
key
.
equals
(
"*"
)){
key
=
"*"
+
key
+
"*"
;
}
for
(
Object
s
:
redisTemplate
.
keys
(
key
))
{
RedisVo
redisVo
=
new
RedisVo
(
s
.
toString
(),
redisTemplate
.
opsForValue
().
get
(
s
.
toString
()).
toString
());
redisVos
.
add
(
redisVo
);
}
Page
<
RedisVo
>
page
=
new
PageImpl
<
RedisVo
>(
PageUtil
.
toPage
(
pageable
.
getPageNumber
(),
pageable
.
getPageSize
(),
redisVos
),
pageable
,
redisVos
.
size
());
return
page
;
}
@Override
public
void
save
(
RedisVo
redisVo
)
{
Jedis
jedis
=
null
;
try
{
jedis
=
pool
.
getResource
();
jedis
.
set
(
redisVo
.
getKey
(),
redisVo
.
getValue
());
}
finally
{
if
(
null
!=
jedis
){
jedis
.
close
();
// 释放资源还给连接池
}
}
redisTemplate
.
opsForValue
().
set
(
redisVo
.
getKey
(),
redisVo
.
getValue
());
}
@Override
public
void
delete
(
String
key
)
{
Jedis
jedis
=
null
;
try
{
jedis
=
pool
.
getResource
();
jedis
.
del
(
key
);
}
finally
{
if
(
null
!=
jedis
){
jedis
.
close
();
// 释放资源还给连接池
}
}
redisTemplate
.
delete
(
key
);
}
@Override
public
void
flushdb
()
{
Jedis
jedis
=
null
;
try
{
jedis
=
pool
.
getResource
();
jedis
.
flushAll
();
}
finally
{
if
(
null
!=
jedis
){
jedis
.
close
();
// 释放资源还给连接池
}
}
redisTemplate
.
getConnectionFactory
().
getConnection
().
flushDb
();
}
}
eladmin-system/src/main/resources/config/application.yml
浏览文件 @
2b931a58
...
...
@@ -24,16 +24,6 @@ spring:
host
:
127.0.0.1
port
:
6379
password
:
jedis
:
pool
:
#最大连接数
max-active
:
100
#最大阻塞等待时间(负数表示没限制)
max-wait
:
2000
#最大空闲
max-idle
:
500
#最小空闲
min-idle
:
8
#连接超时时间
timeout
:
5000
...
...
pom.xml
浏览文件 @
2b931a58
...
...
@@ -70,12 +70,6 @@
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
<exclusions>
<exclusion>
<groupId>
io.lettuce
</groupId>
<artifactId>
lettuce-core
</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--Spring boot end-->
...
...
@@ -231,4 +225,4 @@
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
\ No newline at end of file
</project>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录