Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
d6e63fd7
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d6e63fd7
编写于
5月 12, 2018
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完善RedisService
上级
f0347874
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
43 addition
and
17 deletion
+43
-17
whatsmars-redis/src/main/java/org/hongxi/whatsmars/redis/client/service/RedisMapService.java
...ongxi/whatsmars/redis/client/service/RedisMapService.java
+6
-4
whatsmars-redis/src/main/java/org/hongxi/whatsmars/redis/client/service/RedisService.java
...g/hongxi/whatsmars/redis/client/service/RedisService.java
+5
-0
whatsmars-redis/src/main/java/org/hongxi/whatsmars/redis/client/service/impl/RedisListServiceImpl.java
...smars/redis/client/service/impl/RedisListServiceImpl.java
+1
-4
whatsmars-redis/src/main/java/org/hongxi/whatsmars/redis/client/service/impl/RedisMapServiceImpl.java
...tsmars/redis/client/service/impl/RedisMapServiceImpl.java
+14
-0
whatsmars-redis/src/main/java/org/hongxi/whatsmars/redis/client/service/impl/RedisServiceImpl.java
...whatsmars/redis/client/service/impl/RedisServiceImpl.java
+17
-9
未找到文件。
whatsmars-redis/src/main/java/org/hongxi/whatsmars/redis/client/service/RedisMapService.java
浏览文件 @
d6e63fd7
...
...
@@ -15,12 +15,14 @@ public interface RedisMapService {
List
<
byte
[]>
hMGet
(
String
redisKey
,
List
<
String
>
mapKeys
);
byte
[]
hGet
(
String
redisKey
,
String
mapKey
);
long
hDel
(
String
redisKey
,
List
<
String
>
mapKeys
);
long
hDel
(
String
redisKey
,
byte
[]
mapKey
);
boolean
hSet
(
String
redisKey
,
String
mapKey
,
String
mapValue
);
String
hGetString
(
String
redisKey
,
String
mapKey
);
String
hGet
(
String
redisKey
,
byte
[]
mapKey
);
}
whatsmars-redis/src/main/java/org/hongxi/whatsmars/redis/client/service/RedisService.java
浏览文件 @
d6e63fd7
package
org.hongxi.whatsmars.redis.client.service
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Set
;
public
interface
RedisService
<
T
>
{
...
...
@@ -110,4 +111,8 @@ public interface RedisService<T> {
void
pubMsg
(
String
channel
,
Object
obj
);
Set
<
String
>
getSet
(
String
key
);
long
addSet
(
String
key
,
String
...
values
);
List
<
T
>
multiGet
(
Collection
keys
);
}
whatsmars-redis/src/main/java/org/hongxi/whatsmars/redis/client/service/impl/RedisListServiceImpl.java
浏览文件 @
d6e63fd7
...
...
@@ -17,9 +17,8 @@ public class RedisListServiceImpl implements RedisListService {
private
RedisTemplate
<
String
,
List
<
Object
>>
redisTemplate
;
@Override
public
long
rpush
(
final
byte
[]
key
,
final
byte
[]...
values
)
{
public
long
rpush
(
final
byte
[]
key
,
final
byte
[]...
values
)
{
return
redisTemplate
.
execute
(
new
RedisCallback
<
Long
>()
{
@Override
public
Long
doInRedis
(
RedisConnection
connection
)
throws
DataAccessException
{
return
connection
.
rPush
(
key
,
values
);
...
...
@@ -38,7 +37,6 @@ public class RedisListServiceImpl implements RedisListService {
@Override
public
List
<
byte
[]>
lrange
(
final
byte
[]
key
,
final
long
begin
,
final
long
end
)
{
return
redisTemplate
.
execute
(
new
RedisCallback
<
List
<
byte
[]>>()
{
@Override
public
List
<
byte
[]>
doInRedis
(
RedisConnection
connection
)
throws
DataAccessException
{
return
connection
.
lRange
(
key
,
begin
,
end
);
...
...
@@ -59,7 +57,6 @@ public class RedisListServiceImpl implements RedisListService {
@Override
public
long
del
(
final
byte
[]
key
)
{
return
redisTemplate
.
execute
(
new
RedisCallback
<
Long
>()
{
@Override
public
Long
doInRedis
(
RedisConnection
connection
)
throws
DataAccessException
{
return
connection
.
del
(
key
);
...
...
whatsmars-redis/src/main/java/org/hongxi/whatsmars/redis/client/service/impl/RedisMapServiceImpl.java
浏览文件 @
d6e63fd7
...
...
@@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
java.io.UnsupportedEncodingException
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -16,6 +17,8 @@ import java.util.Set;
@Service
(
"redisMapService"
)
public
class
RedisMapServiceImpl
implements
RedisMapService
{
private
static
final
String
CHARSET
=
"UTF8"
;
@Resource
private
RedisTemplate
<
String
,
Map
<
byte
[],
byte
[]>>
redisTemplate
;
...
...
@@ -112,6 +115,17 @@ public class RedisMapServiceImpl implements RedisMapService {
});
}
@Override
public
String
hGetString
(
String
redisKey
,
String
mapKey
)
{
byte
[]
value
=
hGet
(
redisKey
,
mapKey
);
try
{
return
value
==
null
?
null
:
new
String
(
value
,
CHARSET
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
@Override
public
String
hGet
(
final
String
redisKey
,
final
byte
[]
mapKey
)
{
return
redisTemplate
.
execute
(
new
RedisCallback
<
String
>()
{
...
...
whatsmars-redis/src/main/java/org/hongxi/whatsmars/redis/client/service/impl/RedisServiceImpl.java
浏览文件 @
d6e63fd7
...
...
@@ -20,6 +20,7 @@ import java.io.Serializable;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Set
;
@Service
(
"redisService"
)
...
...
@@ -60,15 +61,16 @@ public class RedisServiceImpl<T> implements RedisService<T> {
public
boolean
set
(
byte
[]
key
,
byte
[]
value
)
{
return
this
.
set
(
key
,
value
,
0L
);
}
@Override
public
boolean
set
(
byte
[]
key
,
T
value
,
long
activeTime
){
ObjectMapper
objectMapper
=
new
ObjectMapper
();
byte
[]
b
=
null
;
try
{
b
=
objectMapper
.
writeValueAsBytes
(
value
);
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
return
false
;
}
return
this
.
set
(
key
,
b
,
activeTime
);
}
...
...
@@ -79,11 +81,11 @@ public class RedisServiceImpl<T> implements RedisService<T> {
public
String
doInRedis
(
RedisConnection
connection
)
throws
DataAccessException
{
try
{
byte
[]
value
=
connection
.
get
(
key
.
getBytes
());
return
value
==
null
?
""
:
new
String
(
value
,
CHARSET
);
return
value
==
null
?
null
:
new
String
(
value
,
CHARSET
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
return
""
;
return
null
;
}
});
}
...
...
@@ -100,13 +102,10 @@ public class RedisServiceImpl<T> implements RedisService<T> {
try
{
return
objectMapper
.
readValue
(
value
,
c
);
}
catch
(
JsonParseException
e
)
{
e
.
printStackTrace
();
}
catch
(
JsonMappingException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
...
...
@@ -117,7 +116,6 @@ public class RedisServiceImpl<T> implements RedisService<T> {
@Override
public
Set
<
String
>
matchKeys
(
String
pattern
)
{
return
redisTemplate
.
keys
(
pattern
);
}
@Override
...
...
@@ -145,7 +143,7 @@ public class RedisServiceImpl<T> implements RedisService<T> {
public
Long
doInRedis
(
RedisConnection
connection
)
throws
DataAccessException
{
long
result
=
0
;
for
(
String
key
:
keys
)
{
result
=
connection
.
del
(
key
.
getBytes
());
result
+
=
connection
.
del
(
key
.
getBytes
());
}
return
result
;
}
...
...
@@ -182,4 +180,14 @@ public class RedisServiceImpl<T> implements RedisService<T> {
return
stringRedisTemplate
.
opsForSet
().
members
(
key
);
}
@Override
public
long
addSet
(
String
key
,
String
...
values
)
{
return
stringRedisTemplate
.
opsForSet
().
add
(
key
,
values
);
}
@Override
public
List
<
T
>
multiGet
(
Collection
keys
)
{
return
redisTemplate
.
opsForValue
().
multiGet
(
keys
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录