Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
Z
zion
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
zion
Commits
af3eb65a
提交
af3eb65a
authored
10月 26, 2019
作者:
luojie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改RedisConfig,测试Redis
上级
15724fe1
全部展开
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
786 行增加
和
15 行删除
+786
-15
pom.xml
pom.xml
+16
-2
ZionApplication.java
src/main/java/com/diaoyun/zion/ZionApplication.java
+6
-1
RedisController.java
...in/java/com/diaoyun/zion/master/base/RedisController.java
+49
-0
RedisConfig.java
...main/java/com/diaoyun/zion/master/config/RedisConfig.java
+100
-10
UserEntity.java
src/main/java/com/diaoyun/zion/master/entity/UserEntity.java
+52
-0
RedisUtil.java
src/main/java/com/diaoyun/zion/master/util/RedisUtil.java
+561
-0
application.yml
src/main/resources/application.yml
+2
-2
没有找到文件。
pom.xml
浏览文件 @
af3eb65a
...
@@ -235,8 +235,22 @@
...
@@ -235,8 +235,22 @@
<artifactId>
stripe-java
</artifactId>
<artifactId>
stripe-java
</artifactId>
<version>
11.6.1
</version>
<version>
11.6.1
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter
</artifactId>
<version>
RELEASE
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter
</artifactId>
<version>
RELEASE
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/com/diaoyun/zion/ZionApplication.java
浏览文件 @
af3eb65a
package
com
.
diaoyun
.
zion
;
package
com
.
diaoyun
.
zion
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.web.servlet.support.SpringBootServletInitializer
;
import
org.springframework.boot.web.servlet.support.SpringBootServletInitializer
;
...
@@ -8,7 +10,6 @@ import org.springframework.cache.annotation.EnableCaching;
...
@@ -8,7 +10,6 @@ import org.springframework.cache.annotation.EnableCaching;
@SpringBootApplication
@SpringBootApplication
@EnableCaching
@EnableCaching
public
class
ZionApplication
extends
SpringBootServletInitializer
{
public
class
ZionApplication
extends
SpringBootServletInitializer
{
//tomcat 设置
//tomcat 设置
/*@Override
/*@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
...
@@ -18,5 +19,9 @@ public class ZionApplication extends SpringBootServletInitializer {
...
@@ -18,5 +19,9 @@ public class ZionApplication extends SpringBootServletInitializer {
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ZionApplication
.
class
,
args
);
SpringApplication
.
run
(
ZionApplication
.
class
,
args
);
}
}
@Test
public
void
test
()
throws
Exception
{
}
}
}
src/main/java/com/diaoyun/zion/master/base/RedisController.java
0 → 100644
浏览文件 @
af3eb65a
package
com
.
diaoyun
.
zion
.
master
.
base
;
import
com.diaoyun.zion.master.entity.UserEntity
;
import
com.diaoyun.zion.master.util.RedisUtil
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
java.util.Date
;
/**
* @program: springbootdemo
* @Date: 2019/1/25 15:03
* @Author: Mr.Zheng
* @Description:
*/
@RequestMapping
(
"/redis"
)
@RestController
public
class
RedisController
{
private
static
int
ExpireTime
=
60
;
// redis中存储的过期时间60s
@Resource
private
RedisUtil
redisUtil
;
@RequestMapping
(
"set"
)
public
boolean
redisset
(
String
key
,
String
value
){
UserEntity
userEntity
=
new
UserEntity
();
userEntity
.
setId
(
Long
.
valueOf
(
1
));
userEntity
.
setGuid
(
String
.
valueOf
(
1
));
userEntity
.
setName
(
"zhangsan"
);
userEntity
.
setAge
(
String
.
valueOf
(
20
));
userEntity
.
setCreateTime
(
new
Date
());
//return redisUtil.set(key,userEntity,ExpireTime);
return
redisUtil
.
set
(
key
,
value
);
}
@RequestMapping
(
"get"
)
public
Object
redisget
(
String
key
){
return
redisUtil
.
get
(
key
);
}
@RequestMapping
(
"expire"
)
public
boolean
expire
(
String
key
){
return
redisUtil
.
expire
(
key
,
ExpireTime
);
}
}
\ No newline at end of file
src/main/java/com/diaoyun/zion/master/config/RedisConfig.java
浏览文件 @
af3eb65a
...
@@ -7,26 +7,116 @@ import org.springframework.data.redis.core.RedisTemplate;
...
@@ -7,26 +7,116 @@ import org.springframework.data.redis.core.RedisTemplate;
import
org.springframework.data.redis.listener.RedisMessageListenerContainer
;
import
org.springframework.data.redis.listener.RedisMessageListenerContainer
;
import
org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.springframework.cache.annotation.CachingConfigurerSupport
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.*
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
@Configuration
@Configuration
public
class
RedisConfig
<
T
>
{
@EnableCaching
//开启注解
public
class
RedisConfig
<
T
>
extends
CachingConfigurerSupport
{
@Bean
RedisMessageListenerContainer
container
(
RedisConnectionFactory
connectionFactory
)
{
RedisMessageListenerContainer
container
=
new
RedisMessageListenerContainer
();
container
.
setConnectionFactory
(
connectionFactory
);
return
container
;
}
/**
* retemplate相关配置
* @param factory
* @return
*/
@Bean
(
"redisTemplate"
)
@Bean
(
"redisTemplate"
)
public
RedisTemplate
<
String
,
T
>
redisTemplate
(
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
RedisConnectionFactory
factory
)
{
RedisConnectionFactory
redisConnectionFactory
)
{
RedisTemplate
<
String
,
T
>
template
=
new
RedisTemplate
<>();
RedisTemplate
<
String
,
Object
>
template
=
new
RedisTemplate
<>();
template
.
setConnectionFactory
(
redisConnectionFactory
);
// 配置连接工厂
template
.
setConnectionFactory
(
factory
);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
Jackson2JsonRedisSerializer
jacksonSeial
=
new
Jackson2JsonRedisSerializer
(
Object
.
class
);
ObjectMapper
om
=
new
ObjectMapper
();
// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
om
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
om
.
enableDefaultTyping
(
ObjectMapper
.
DefaultTyping
.
NON_FINAL
);
jacksonSeial
.
setObjectMapper
(
om
);
// 值采用json序列化
template
.
setValueSerializer
(
jacksonSeial
);
//使用StringRedisSerializer来序列化和反序列化redis的key值
template
.
setKeySerializer
(
new
StringRedisSerializer
());
template
.
setKeySerializer
(
new
StringRedisSerializer
());
template
.
setValueSerializer
(
new
GenericJackson2JsonRedisSerializer
());
// 设置hash key 和value序列化模式
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashValueSerializer
(
jacksonSeial
);
template
.
afterPropertiesSet
();
return
template
;
return
template
;
}
}
/**
* 对hash类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
HashOperations
<
String
,
String
,
Object
>
hashOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForHash
();
}
/**
* 对redis字符串类型数据操作
*
* @param redisTemplate
* @return
*/
@Bean
@Bean
RedisMessageListenerContainer
container
(
RedisConnectionFactory
connectionFactory
)
{
public
ValueOperations
<
String
,
Object
>
valueOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
RedisMessageListenerContainer
container
=
new
RedisMessageListenerContainer
();
return
redisTemplate
.
opsForValue
();
container
.
setConnectionFactory
(
connectionFactory
);
}
return
container
;
/**
* 对链表类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
ListOperations
<
String
,
Object
>
listOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForList
();
}
/**
* 对无序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
SetOperations
<
String
,
Object
>
setOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForSet
();
}
/**
* 对有序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
ZSetOperations
<
String
,
Object
>
zSetOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForZSet
();
}
}
}
}
src/main/java/com/diaoyun/zion/master/entity/UserEntity.java
0 → 100644
浏览文件 @
af3eb65a
package
com
.
diaoyun
.
zion
.
master
.
entity
;
import
java.io.Serializable
;
import
java.util.Date
;
public
class
UserEntity
implements
Serializable
{
private
Long
id
;
private
String
guid
;
private
String
name
;
private
String
age
;
private
Date
createTime
;
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getGuid
()
{
return
guid
;
}
public
void
setGuid
(
String
guid
)
{
this
.
guid
=
guid
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getAge
()
{
return
age
;
}
public
void
setAge
(
String
age
)
{
this
.
age
=
age
;
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
}
\ No newline at end of file
src/main/java/com/diaoyun/zion/master/util/RedisUtil.java
0 → 100644
浏览文件 @
af3eb65a
差异被折叠。
点击展开。
src/main/resources/application.yml
浏览文件 @
af3eb65a
...
@@ -41,9 +41,9 @@ spring:
...
@@ -41,9 +41,9 @@ spring:
# username: root
# username: root
# password: 1234
# password: 1234
#测试环境
#测试环境
url
:
jdbc:mysql://
47.106.242.175
:3306/chinafrica?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useSSL=false
url
:
jdbc:mysql://
localhost
:3306/chinafrica?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useSSL=false
username
:
root
username
:
root
password
:
diaoyun666
password
:
root
# 连接池配置
# 连接池配置
initial-size
:
5
initial-size
:
5
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论