Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
81608051
Commit
81608051
authored
Jul 16, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of 47.100.44.39:tp-backend/tanpu-community into dev
parents
a2f16cb8
cf95830f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
30 deletions
+91
-30
RedisCache.java
...e/src/main/java/com/tanpu/community/cache/RedisCache.java
+71
-0
CacheConfig.java
...src/main/java/com/tanpu/community/config/CacheConfig.java
+14
-0
SearchController.java
...java/com/tanpu/community/controller/SearchController.java
+2
-0
TestController.java
...n/java/com/tanpu/community/controller/TestController.java
+0
-30
SearchManager.java
.../main/java/com/tanpu/community/manager/SearchManager.java
+2
-0
ESService.java
...main/java/com/tanpu/community/service/base/ESService.java
+2
-0
No files found.
community-service/src/main/java/com/tanpu/community/cache/RedisCache.java
0 → 100644
View file @
81608051
package
com
.
tanpu
.
community
.
cache
;
import
com.alibaba.fastjson.JSON
;
import
com.tanpu.common.redis.RedisHelper
;
import
com.tanpu.common.redis.RedisKeyHelper
;
import
com.tanpu.community.util.SpringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Component
;
import
java.time.Duration
;
import
java.util.List
;
import
java.util.function.Supplier
;
public
class
RedisCache
{
private
String
cacheName
;
private
RedisHelper
redisHelper
;
public
<
T
>
T
getObject
(
String
key
,
Integer
expireSeconds
,
Supplier
<
T
>
func
,
Class
<
T
>
clz
)
{
String
value
=
get
(
key
);
// todo 考虑缓存穿透的问题.
if
(
StringUtils
.
isNotBlank
(
value
))
{
return
JSON
.
parseObject
(
value
,
clz
);
}
T
ret
=
func
.
get
();
put
(
key
,
ret
,
expireSeconds
);
return
ret
;
}
public
<
T
>
List
<
T
>
getList
(
String
key
,
Integer
expireSeconds
,
Supplier
<
List
<
T
>>
func
,
Class
<
T
>
clz
)
{
String
value
=
get
(
key
);
if
(
StringUtils
.
isNotBlank
(
value
))
{
return
JSON
.
parseArray
(
value
,
clz
);
}
List
<
T
>
ret
=
func
.
get
();
put
(
key
,
ret
,
expireSeconds
);
return
ret
;
}
private
String
get
(
String
key
)
{
key
=
cacheName
+
":"
+
key
;
return
redisHelper
.
get
(
key
);
}
private
void
put
(
String
key
,
Object
obj
,
Integer
expireSeconds
)
{
if
(
obj
==
null
)
return
;
key
=
cacheName
+
":"
+
key
;
String
value
=
JSON
.
toJSONString
(
obj
);
if
(
expireSeconds
==
0
)
{
redisHelper
.
set
(
key
,
value
);
}
else
{
redisHelper
.
set
(
key
,
value
,
Duration
.
ofSeconds
(
expireSeconds
));
}
}
public
static
class
Builder
{
RedisCache
cache
=
new
RedisCache
();
public
Builder
cacheName
(
String
cacheName
)
{
cache
.
cacheName
=
cacheName
;
cache
.
redisHelper
=
SpringUtils
.
getBean
(
RedisHelper
.
class
);
}
public
RedisCache
build
()
{
return
cache
;
}
}
}
community-service/src/main/java/com/tanpu/community/config/CacheConfig.java
0 → 100644
View file @
81608051
package
com
.
tanpu
.
community
.
config
;
import
com.tanpu.community.cache.RedisCache
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
public
class
CacheConfig
{
@Bean
public
RedisCache
redisCache
()
{
return
new
RedisCache
.
Builder
().
cacheName
(
"community2"
).
build
();
}
}
community-service/src/main/java/com/tanpu/community/controller/SearchController.java
0 → 100644
View file @
81608051
package
com
.
tanpu
.
community
.
controller
;
public
class
SearchController
{
}
community-service/src/main/java/com/tanpu/community/controller/TestController.java
deleted
100644 → 0
View file @
a2f16cb8
package
com
.
tanpu
.
community
.
controller
;
import
com.tanpu.community.manager.KafkaManager
;
import
com.tanpu.community.service.UserInfoService
;
import
com.tanpu.community.service.VisitSummaryService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
@RestController
@Slf4j
@RequestMapping
(
value
=
"/api/test"
)
public
class
TestController
{
@Autowired
private
KafkaManager
kafkaManager
;
@Autowired
private
VisitSummaryService
visitSummaryService
;
@Autowired
private
UserInfoService
userInfoService
;
@GetMapping
(
value
=
"/1"
)
@ResponseBody
public
Object
sendKafka
()
{
return
userInfoService
.
queryUserById
(
"USER_INFO15912897523789"
);
}
}
community-service/src/main/java/com/tanpu/community/manager/SearchManager.java
0 → 100644
View file @
81608051
package
com
.
tanpu
.
community
.
manager
;
public
class
SearchManager
{
}
community-service/src/main/java/com/tanpu/community/service/base/ESService.java
0 → 100644
View file @
81608051
package
com
.
tanpu
.
community
.
service
.
base
;
public
class
ESService
{
}
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