Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
6cec7633
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 搜索 >>
提交
6cec7633
编写于
6月 23, 2017
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
redis test
上级
011fd2cf
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
85 addition
and
88 deletion
+85
-88
whatsmars-redis/pom.xml
whatsmars-redis/pom.xml
+12
-0
whatsmars-redis/src/main/java/com/itlong/whatsmars/redis/client/cluster/Demo.java
.../java/com/itlong/whatsmars/redis/client/cluster/Demo.java
+0
-29
whatsmars-redis/src/main/java/com/itlong/whatsmars/redis/client/readwrite/Demo.java
...ava/com/itlong/whatsmars/redis/client/readwrite/Demo.java
+0
-26
whatsmars-redis/src/main/java/com/itlong/whatsmars/redis/client/singleton/Demo.java
...ava/com/itlong/whatsmars/redis/client/singleton/Demo.java
+0
-33
whatsmars-redis/src/test/java/com/itlong/whatsmars/redis/client/Demo.java
...src/test/java/com/itlong/whatsmars/redis/client/Demo.java
+73
-0
whatsmars-redis/src/test/resources/spring-redis.xml
whatsmars-redis/src/test/resources/spring-redis.xml
+0
-0
未找到文件。
whatsmars-redis/pom.xml
浏览文件 @
6cec7633
...
...
@@ -29,6 +29,18 @@
<groupId>
org.springframework
</groupId>
<artifactId>
spring-aop
</artifactId>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
4.11
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-test
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
...
...
whatsmars-redis/src/main/java/com/itlong/whatsmars/redis/client/cluster/Demo.java
已删除
100644 → 0
浏览文件 @
011fd2cf
package
com.itlong.whatsmars.redis.client.cluster
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.stereotype.Component
;
import
redis.clients.jedis.JedisCluster
;
/**
* Created by javahongxi on 2017/6/22.
*/
@Component
public
class
Demo
{
@Autowired
@Qualifier
(
"redisClusterClient"
)
private
JedisCluster
redisClient
;
public
void
test
()
{
String
cacheContent
=
null
;
try
{
cacheContent
=
redisClient
.
get
(
"hello_world"
);
}
catch
(
Exception
e
)
{
//如果异常,你可以决定是否忽略
}
if
(
cacheContent
==
null
)
{
//如果cache中不存在,或者redis异常
}
}
}
whatsmars-redis/src/main/java/com/itlong/whatsmars/redis/client/readwrite/Demo.java
已删除
100644 → 0
浏览文件 @
011fd2cf
package
com.itlong.whatsmars.redis.client.readwrite
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/**
* Created by javahongxi on 2017/6/22.
*/
@Component
public
class
Demo
{
@Autowired
private
ReadWriteRedisClient
redisClient
;
public
void
test
()
{
String
cacheContent
=
null
;
try
{
cacheContent
=
redisClient
.
get
(
"hello_world"
);
}
catch
(
Exception
e
)
{
//如果异常,你可以决定是否忽略
}
if
(
cacheContent
==
null
)
{
//如果cache中不存在,或者redis异常
}
}
}
whatsmars-redis/src/main/java/com/itlong/whatsmars/redis/client/singleton/Demo.java
已删除
100644 → 0
浏览文件 @
011fd2cf
package
com.itlong.whatsmars.redis.client.singleton
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.stereotype.Component
;
import
redis.clients.jedis.Jedis
;
import
redis.clients.jedis.JedisPool
;
/**
* Created by javahongxi on 2017/6/22.
*/
@Component
public
class
Demo
{
@Autowired
@Qualifier
(
"singletonRedisClient"
)
private
JedisPool
redisClient
;
public
void
test
()
{
Jedis
jedis
=
redisClient
.
getResource
();
String
cacheContent
=
null
;
try
{
cacheContent
=
jedis
.
get
(
"hello_world"
);
}
finally
{
redisClient
.
close
();
}
// 获取redis数据之后,立即释放连接,然后开始进行业务处理
if
(
cacheContent
==
null
)
{
// DB operation
}
// ..
}
}
whatsmars-redis/src/test/java/com/itlong/whatsmars/redis/client/Demo.java
0 → 100644
浏览文件 @
6cec7633
package
com.itlong.whatsmars.redis.client
;
import
com.itlong.whatsmars.redis.client.readwrite.ReadWriteRedisClient
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
redis.clients.jedis.Jedis
;
import
redis.clients.jedis.JedisCluster
;
import
redis.clients.jedis.JedisPool
;
/**
* Created by javahongxi on 2017/6/23.
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
locations
=
"classpath:spring-redis.xml"
)
public
class
Demo
{
@Autowired
@Qualifier
(
"singletonRedisClient"
)
private
JedisPool
singletonRedisClient
;
@Autowired
private
ReadWriteRedisClient
readWriteRedisClient
;
@Autowired
@Qualifier
(
"redisClusterClient"
)
private
JedisCluster
jedisCluster
;
@Test
public
void
testSingleton
()
{
Jedis
jedis
=
singletonRedisClient
.
getResource
();
String
cacheContent
=
null
;
try
{
cacheContent
=
jedis
.
get
(
"hello_world"
);
}
finally
{
singletonRedisClient
.
close
();
}
// 获取redis数据之后,立即释放连接,然后开始进行业务处理
if
(
cacheContent
==
null
)
{
// DB operation
}
// ..
}
@Test
public
void
testReadWrite
()
{
String
cacheContent
=
null
;
try
{
cacheContent
=
readWriteRedisClient
.
get
(
"hello_world"
);
}
catch
(
Exception
e
)
{
//如果异常,你可以决定是否忽略
}
if
(
cacheContent
==
null
)
{
//如果cache中不存在,或者redis异常
}
}
@Test
public
void
testCluster
()
{
String
cacheContent
=
null
;
try
{
cacheContent
=
jedisCluster
.
get
(
"hello_world"
);
}
catch
(
Exception
e
)
{
//如果异常,你可以决定是否忽略
}
if
(
cacheContent
==
null
)
{
//如果cache中不存在,或者redis异常
}
}
}
whatsmars-redis/src/
main
/resources/spring-redis.xml
→
whatsmars-redis/src/
test
/resources/spring-redis.xml
浏览文件 @
6cec7633
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录