Toggle navigation
Toggle navigation
This project
Loading...
Sign in
yoho-search
/
yoho-search-service
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
hugufei
8 years ago
Commit
0de5015f328b4ebcae3163b3063eb4e14f49f7dc
1 parent
ff55558d
为search 单独添加redis
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
11 deletions
service/src/main/java/com/yoho/search/common/RedisCacheService.java
web/src/main/resources/META-INF/spring/spring-search-redis.xml
web/src/main/resources/config.properties
web/src/main/webapp/META-INF/autoconf/config.properties
service/src/main/java/com/yoho/search/common/RedisCacheService.java
View file @
0de5015
...
...
@@ -22,10 +22,10 @@ public class RedisCacheService {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
DownGradeCacheService
.
class
);
@Resource
(
name
=
"yhNoSyncValueOperations"
)
private
YHValueOperations
<
String
,
String
>
yhNoSyncValueOperations
;
@Resource
(
name
=
"yhNoSyncRedisTemplate"
)
private
YHRedisTemplate
<
String
,
String
>
yhNoSyncRedisTemplate
;
@Resource
(
name
=
"searchValueOperations"
)
private
YHValueOperations
<
String
,
String
>
searchValueOperations
;
@Resource
(
name
=
"searchRedisTemplate"
)
private
YHRedisTemplate
<
String
,
String
>
searchRedisTemplate
;
/**
* 序列化保持null值
...
...
@@ -42,7 +42,7 @@ public class RedisCacheService {
public
boolean
exist
(
String
key
)
{
try
{
return
yhNoSync
RedisTemplate
.
hasKey
(
key
);
return
search
RedisTemplate
.
hasKey
(
key
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
return
false
;
...
...
@@ -51,7 +51,7 @@ public class RedisCacheService {
public
<
T
>
T
safeGet
(
String
key
,
Class
<
T
>
clazz
)
{
try
{
String
compressedVal
=
yhNoSync
ValueOperations
.
get
(
key
);
String
compressedVal
=
search
ValueOperations
.
get
(
key
);
if
(
StringUtils
.
isBlank
(
compressedVal
))
{
return
null
;
}
...
...
@@ -70,8 +70,8 @@ public class RedisCacheService {
if
(
StringUtils
.
isBlank
(
compressedVal
))
{
return
;
}
yhNoSyncValueOperations
.
set
(
key
,
compressedVal
);
yhNoSyncRedisTemplate
.
longExpire
(
key
,
expiredTimeInMinute
,
TimeUnit
.
MINUTES
);
searchValueOperations
.
set
(
key
,
compressedVal
);
searchRedisTemplate
.
longExpire
(
key
,
expiredTimeInMinute
,
TimeUnit
.
MINUTES
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
...
...
@@ -84,10 +84,10 @@ public class RedisCacheService {
if
(
StringUtils
.
isBlank
(
compressedVal
))
{
return
false
;
}
if
(!
yhNoSync
ValueOperations
.
setIfAbsent
(
key
,
compressedVal
)){
if
(!
search
ValueOperations
.
setIfAbsent
(
key
,
compressedVal
)){
return
false
;
}
yhNoSync
RedisTemplate
.
longExpire
(
key
,
expiredTimeInMinute
,
TimeUnit
.
MINUTES
);
search
RedisTemplate
.
longExpire
(
key
,
expiredTimeInMinute
,
TimeUnit
.
MINUTES
);
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
...
...
@@ -97,7 +97,7 @@ public class RedisCacheService {
public
void
safeDelete
(
String
key
)
{
try
{
yhNoSync
RedisTemplate
.
delete
(
key
);
search
RedisTemplate
.
delete
(
key
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
...
...
web/src/main/resources/META-INF/spring/spring-search-redis.xml
0 → 100644
View file @
0de5015
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:p=
"http://www.springframework.org/schema/p"
xmlns=
"http://www.springframework.org/schema/beans"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
>
<!-- redis template definition -->
<bean
id=
"searchStringRedisSerializer"
class=
"org.springframework.data.redis.serializer.StringRedisSerializer"
/>
<!-- pool config -->
<bean
id=
"searchJedisPoolConfig"
class=
"redis.clients.jedis.JedisPoolConfig"
>
<property
name=
"maxTotal"
value=
"${redis.pool.maxTotal:50}"
/>
<property
name=
"maxIdle"
value=
"${redis.pool.maxIdle:20}"
/>
<property
name=
"minIdle"
value=
"${redis.pool.minIdle:20}"
></property>
<property
name=
"maxWaitMillis"
value=
"${redis.pool.maxWaitMillis:2000}"
/>
<property
name=
"testOnBorrow"
value=
"${redis.pool.testOnBorrow:false}"
/>
<property
name=
"testWhileIdle"
value=
"${redis.pool.testWhileIdle:false}"
></property>
</bean>
<!-- 连接池 -->
<bean
id=
"searchJedisConnectionFactory"
class=
"org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:timeout=
"100"
p:poolConfig-ref=
"searchJedisPoolConfig"
p:hostName=
"${redis.search.proxy.address}"
p:port=
"${redis.search.proxy.port}"
p:password=
"${redis.search.proxy.auth}"
primary=
"true"
/>
<!-- 读写模板 -->
<bean
id=
"searchRedisTemplate"
class=
"com.yoho.core.redis.YHRedisTemplate"
primary=
"true"
p:connectionFactory-ref=
"searchJedisConnectionFactory"
p:keySerializer-ref=
"searchStringRedisSerializer"
p:valueSerializer-ref=
"searchStringRedisSerializer"
p:hashKeySerializer-ref=
"searchStringRedisSerializer"
p:hashValueSerializer-ref=
"searchStringRedisSerializer"
p:redisCacheClean-ref=
"redisCacheClean"
/>
<!-- 只读模板 -->
<bean
id=
"searchRedisTemplateReadOnly"
class=
"com.yoho.core.redis.YHRedisTemplate"
primary=
"false"
p:connectionFactory-ref=
"searchJedisConnectionFactory"
p:keySerializer-ref=
"searchStringRedisSerializer"
p:valueSerializer-ref=
"searchStringRedisSerializer"
p:hashKeySerializer-ref=
"searchStringRedisSerializer"
p:hashValueSerializer-ref=
"searchStringRedisSerializer"
p:redisCacheClean-ref=
"redisCacheClean"
/>
<bean
id=
"searchValueOperations"
class=
"com.yoho.core.redis.YHValueOperations"
primary=
"true"
p:hashOperations-ref=
"searchRedisTemplate"
p:hashOperationsReadOnly-ref=
"searchRedisTemplateReadOnly"
p:redisCacheClean-ref=
"redisCacheClean"
/>
<bean
id=
"searchHashOperations"
class=
"com.yoho.core.redis.YHHashOperations"
primary=
"true"
p:hashOperations-ref=
"searchRedisTemplate"
p:hashOperationsReadOnly-ref=
"searchRedisTemplateReadOnly"
p:redisCacheClean-ref=
"redisCacheClean"
/>
</beans>
\ No newline at end of file
...
...
web/src/main/resources/config.properties
View file @
0de5015
...
...
@@ -15,6 +15,11 @@ bigDataRedis-search.proxy.address=test-bigdata-redis-1903805580.cn-north-1.elb.a
bigDataRedis-
search.proxy.port
=
6379
bigDataRedis-
search.proxy.auth
=
#search redis
redis.search.proxy.address = 192.168.102.211
redis.search.proxy.port
=
6379
redis.search.proxy.auth
=
#search
search.es.cluster.name=yohosearch_test
search.es.servers
=
192.168.102.209:9300 192.168.102.216:9300
...
...
web/src/main/webapp/META-INF/autoconf/config.properties
View file @
0de5015
...
...
@@ -15,6 +15,11 @@ bigDataRedis-search.proxy.address=${bigDataRedis.proxy.address}
bigDataRedis-
search.proxy.port
=
${bigDataRedis.proxy.port}
bigDataRedis-
search.proxy.auth
=
${bigDataRedis.proxy.auth}
#search redis
redis.search.proxy.address
=
${redis.search.proxy.address}
redis.search.proxy.port
=
${redis.search.proxy.port}
redis.search.proxy.auth
=
${redis.search.proxy.auth}
#es.cluster
search.es.cluster.name
=
${search.es.cluster.name}
search.es.servers
=
${search.es.servers}
...
...
Please
register
or
login
to post a comment