Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
push-message
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liucheng
push-message
Commits
fbe30872
Commit
fbe30872
authored
Jan 25, 2022
by
renandong
🇨🇳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1,修改redis手动注入工厂
parent
ac90a5e3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
137 additions
and
11 deletions
+137
-11
pom.xml
pom.xml
+8
-2
RedisConfig.java
src/main/java/com/weface/config/RedisConfig.java
+38
-0
RedisProperties.java
src/main/java/com/weface/config/RedisProperties.java
+82
-0
UserTagsTask.java
src/main/java/com/weface/task/UserTagsTask.java
+1
-1
application.yml
src/main/resources/application.yml
+8
-8
No files found.
pom.xml
View file @
fbe30872
...
...
@@ -49,8 +49,14 @@
<version>
${lombok.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-redis
</artifactId>
<version>
2.4.3
</version>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
<version>
3.3.0
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
src/main/java/com/weface/config/RedisConfig.java
View file @
fbe30872
...
...
@@ -3,9 +3,16 @@ package com.weface.config;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.connection.RedisSentinelConfiguration
;
import
org.springframework.data.redis.connection.RedisStandaloneConfiguration
;
import
org.springframework.data.redis.connection.jedis.JedisConnectionFactory
;
import
org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
...
...
@@ -16,6 +23,36 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public
class
RedisConfig
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
RedisConfig
.
class
);
@Autowired
RedisProperties
redisProperties
;
@Bean
public
JedisConnectionFactory
factory
()
{
RedisStandaloneConfiguration
connectionConf
=
new
RedisStandaloneConfiguration
();
connectionConf
.
setHostName
(
redisProperties
.
getHostname
());
connectionConf
.
setDatabase
(
redisProperties
.
getDatabase
());
connectionConf
.
setPort
(
redisProperties
.
getPort
());
JedisConnectionFactory
factory
=
new
JedisConnectionFactory
(
connectionConf
);
factory
.
getPoolConfig
().
setMaxTotal
(
redisProperties
.
getMaxTotal
());
factory
.
getPoolConfig
().
setMaxIdle
(
redisProperties
.
getMaxIdle
());
factory
.
getPoolConfig
().
setMinIdle
(
redisProperties
.
getMinIdle
());
return
factory
;
}
public
RedisConnectionFactory
lettuceConnectionFactory
()
{
RedisSentinelConfiguration
sentinelConfig
=
new
RedisSentinelConfiguration
()
.
master
(
"mymaster"
)
.
sentinel
(
"127.0.0.1"
,
26379
)
.
sentinel
(
"127.0.0.1"
,
26380
);
return
new
LettuceConnectionFactory
(
sentinelConfig
);
}
@Bean
@SuppressWarnings
(
"all"
)
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
RedisConnectionFactory
factory
)
{
...
...
@@ -39,4 +76,5 @@ public class RedisConfig {
return
template
;
}
}
src/main/java/com/weface/config/RedisProperties.java
0 → 100644
View file @
fbe30872
package
com
.
weface
.
config
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
@ConfigurationProperties
(
prefix
=
"gexiang.redis"
)
@Component
public
class
RedisProperties
{
/**
* redis hostname
*/
private
String
hostname
;
/**
* redis database
*/
private
int
database
;
/**
* redis port
*/
private
int
port
;
/**
* redis max channel
*/
private
int
maxTotal
;
/**
* redis max wait channel
*/
private
int
maxIdle
;
/**
* redis min wait channel
*/
private
int
minIdle
;
public
String
getHostname
()
{
return
hostname
;
}
public
void
setHostname
(
String
hostname
)
{
this
.
hostname
=
hostname
;
}
public
int
getDatabase
()
{
return
database
;
}
public
void
setDatabase
(
int
database
)
{
this
.
database
=
database
;
}
public
int
getPort
()
{
return
port
;
}
public
void
setPort
(
int
port
)
{
this
.
port
=
port
;
}
public
int
getMaxTotal
()
{
return
maxTotal
;
}
public
void
setMaxTotal
(
int
maxTotal
)
{
this
.
maxTotal
=
maxTotal
;
}
public
int
getMaxIdle
()
{
return
maxIdle
;
}
public
void
setMaxIdle
(
int
maxIdle
)
{
this
.
maxIdle
=
maxIdle
;
}
public
int
getMinIdle
()
{
return
minIdle
;
}
public
void
setMinIdle
(
int
minIdle
)
{
this
.
minIdle
=
minIdle
;
}
}
src/main/java/com/weface/task/UserTagsTask.java
View file @
fbe30872
...
...
@@ -55,7 +55,7 @@ public class UserTagsTask {
/**
* 更新用户标签
*/
@Scheduled
(
cron
=
"0
18 10 * * ?
"
)
@Scheduled
(
cron
=
"0
20 11 * * ?
"
)
public
void
updateUserTags
()
{
try
{
//获取每次处理的id起始值
...
...
src/main/resources/application.yml
View file @
fbe30872
...
...
@@ -27,14 +27,6 @@ spring:
enabled
:
true
mvc
:
throw-exception-if-no-handler-found
:
true
redis
:
host
:
172.21.6.6
database
:
0
port
:
6379
maxTotal
:
1000
maxIdle
:
50
minIdle
:
10
timeout
:
1s
getui
:
apps
:
{
...
...
@@ -64,5 +56,13 @@ mybatis-plus:
jdbc-type-for-null
:
'
null'
gexiang
:
redis
:
# hostname: 172.21.6.6
hostname
:
127.0.0.1
database
:
0
port
:
6379
maxTotal
:
1000
maxIdle
:
50
minIdle
:
10
user_tag_id
:
251696
push_max_size
:
10000
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment