Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
zhangshaowu
/
pipi-helper
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit fdb24f2c
authored
Oct 15, 2022
by
zhaolianjie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
加入redisUtil
1 parent
1ddc9a15
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
25 deletions
src/main/java/com/pipihelper/project/feishu/dto/RedisPoolConfig.java
src/main/java/com/pipihelper/project/feishu/dto/RedisPoolConfig.java
View file @
fdb24f2
package
com
.
pipihelper
.
project
.
feishu
.
dto
;
package
com
.
pipihelper
.
project
.
feishu
.
dto
;
import
com.alibaba.fastjson.support.spring.FastJsonRedisSerializer
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
@Configuration
@Configuration
public
class
RedisPoolConfig
{
public
class
RedisPoolConfig
{
@Bean
@Bean
@ConditionalOnMissingBean
(
name
=
"redisTemplate"
)
@ConditionalOnMissingBean
(
name
=
"redisTemplate"
)
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
RedisConnectionFactory
redisConnectionFactory
)
{
public
RedisTemplate
redisTemplate
(
RedisConnectionFactory
redisConnectionFactory
)
{
RedisTemplate
redisTemplate
=
new
RedisTemplate
();
RedisTemplate
<
String
,
Object
>
template
=
new
RedisTemplate
<>();
redisTemplate
.
setKeySerializer
(
new
StringRedisSerializer
());
//value序列器
//使用fastjson序列化
redisTemplate
.
setValueSerializer
(
new
GenericJackson2JsonRedisSerializer
());
//Hash类型 key序列器
FastJsonRedisSerializer
fastJsonRedisSerializer
=
new
FastJsonRedisSerializer
(
Object
.
class
);
redisTemplate
.
setHashKeySerializer
(
new
StringRedisSerializer
());
//Hash类型 value序列器
// value值的序列化采用fastJsonRedisSerializer
redisTemplate
.
setHashValueSerializer
(
new
GenericJackson2JsonRedisSerializer
());
redisTemplate
.
setConnectionFactory
(
redisConnectionFactory
);
template
.
setValueSerializer
(
fastJsonRedisSerializer
);
return
redisTemplate
;
template
.
setHashValueSerializer
(
fastJsonRedisSerializer
);
// key的序列化采用StringRedisSerializer
template
.
setKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
template
.
setConnectionFactory
(
redisConnectionFactory
);
return
template
;
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment