Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
matrix-sample
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mall
arch
matrix-sample
Commits
0d225da4
Commit
0d225da4
authored
Mar 21, 2020
by
liqiuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善demo
parent
8798fd1d
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
618 additions
and
312 deletions
+618
-312
pom.xml
matrix-sample-redis/matrix-sample-redis-biz/pom.xml
+19
-0
Person.java
matrix-sample-redis/matrix-sample-redis-biz/src/main/java/com/secoo/mall/redis/Person.java
+12
-18
PersonService.java
matrix-sample-redis/matrix-sample-redis-biz/src/main/java/com/secoo/mall/redis/PersonService.java
+4
-5
pom.xml
matrix-sample-redis/matrix-sample-redis-spring/pom.xml
+35
-0
RedisClusterTest.java
matrix-sample-redis/matrix-sample-redis-spring/src/main/java/com/secoo/mall/redis/RedisClusterTest.java
+205
-0
RedisTest.java
matrix-sample-redis/matrix-sample-redis-spring/src/main/java/com/secoo/mall/redis/RedisTest.java
+24
-170
redis-cluster.properties
matrix-sample-redis/matrix-sample-redis-spring/src/main/resources/redis-cluster.properties
+10
-10
spring-jedis-alone-config-sample.xml
matrix-sample-redis/matrix-sample-redis-spring/src/main/resources/spring-jedis-alone-config-sample.xml
+19
-46
spring-jedis-cluster-config-sample.xml
matrix-sample-redis/matrix-sample-redis-spring/src/main/resources/spring-jedis-cluster-config-sample.xml
+8
-6
spring-lettuce-alone-config-sample.xml
matrix-sample-redis/matrix-sample-redis-spring/src/main/resources/spring-lettuce-alone-config-sample.xml
+29
-56
spring-lettuce-cluster-config-sample.xml
matrix-sample-redis/matrix-sample-redis-spring/src/main/resources/spring-lettuce-cluster-config-sample.xml
+104
-0
pom.xml
matrix-sample-redis/matrix-sample-redis-starter/pom.xml
+15
-0
RedisSampleApplication.java
matrix-sample-redis/matrix-sample-redis-starter/src/main/java/com/secoo/mall/redis/RedisSampleApplication.java
+37
-1
MuliRedisConfig.java
matrix-sample-redis/matrix-sample-redis-starter/src/main/java/com/secoo/mall/redis/config/MuliRedisConfig.java
+44
-0
application.yml
matrix-sample-redis/matrix-sample-redis-starter/src/main/resources/application.yml
+11
-0
pom.xml
matrix-sample-redis/pom.xml
+32
-0
pom.xml
matrix-sample-rocketmq/matrix-sample-rocketmq-spring/pom.xml
+10
-0
No files found.
matrix-sample-redis/matrix-sample-redis-biz/pom.xml
View file @
0d225da4
...
...
@@ -10,6 +10,24 @@
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
matrix-sample-redis-biz
</artifactId>
<dependencies>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context
</artifactId>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-core
</artifactId>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-classic
</artifactId>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
matrix-sample-redis/matrix-sample-redis-biz/src/main/java/com/secoo/mall/redis/Person.java
View file @
0d225da4
/**
* Created by Administrator on 2018/1/16.
*/
package
com
.
secooframework
.
redis
;
package
com
.
secoo
.
mall
.
redis
;
import
lombok.Data
;
import
java.util.Date
;
...
...
@@ -11,6 +13,7 @@ import java.util.Date;
* @author Administrator
* @create 2018-01-16 11:19
**/
@Data
public
class
Person
{
/**
...
...
@@ -23,9 +26,16 @@ public class Person {
private
String
loginName
;
/**
* 用户名
*/
private
String
userName
;
/**
* 部门名称
*/
private
String
deptName
;
// private String deptName;
/**
* 操作时间
...
...
@@ -48,13 +58,6 @@ public class Person {
this
.
loginName
=
loginName
;
}
public
String
getDeptName
()
{
return
deptName
;
}
public
void
setDeptName
(
String
deptName
)
{
this
.
deptName
=
deptName
;
}
public
Date
getOperDate
()
{
return
operDate
;
...
...
@@ -65,13 +68,4 @@ public class Person {
}
@Override
public
String
toString
()
{
return
"Person{"
+
"id="
+
id
+
", loginName='"
+
loginName
+
'\''
+
", deptName='"
+
deptName
+
'\''
+
", operDate="
+
operDate
+
'}'
;
}
}
matrix-sample-redis/matrix-sample-redis-biz/src/main/java/com/secoo/mall/redis/PersonService.java
View file @
0d225da4
/**
* Created by Administrator on 2018/1/17.
*/
package
com
.
secoo
framework
.
redis
;
package
com
.
secoo
.
mall
.
redis
;
import
com.secooframework.redis.annotation.RedisCache
;
import
java.util.Date
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
/**
* aa
*
...
...
@@ -20,12 +20,11 @@ public class PersonService {
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
PersonService
.
class
);
@RedisCache
(
expired
=
60L
,
key
=
"'frame:PersonTest:'+#id"
)
public
Person
get
(
Long
id
)
{
logger
.
info
(
"get;{}"
,
id
);
Person
p
=
new
Person
();
p
.
setOperDate
(
new
Date
());
p
.
setDeptName
(
"ddd"
);
//
p.setDeptName("ddd");
p
.
setId
(
id
);
return
p
;
}
...
...
matrix-sample-redis/matrix-sample-redis-spring/pom.xml
View file @
0d225da4
...
...
@@ -10,6 +10,40 @@
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
matrix-sample-redis-spring
</artifactId>
<dependencies>
<dependency>
<groupId>
com.secoo.mall
</groupId>
<artifactId>
matrix-datahelper-redis-core
</artifactId>
</dependency>
<dependency>
<groupId>
com.secoo.mall
</groupId>
<artifactId>
matrix-sample-redis-biz
</artifactId>
</dependency>
<dependency>
<groupId>
org.aspectj
</groupId>
<artifactId>
aspectjweaver
</artifactId>
</dependency>
<dependency>
<groupId>
io.lettuce
</groupId>
<artifactId>
lettuce-core
</artifactId>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-test
</artifactId>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
matrix-sample-redis/matrix-sample-redis-spring/src/main/java/com/secoo/mall/redis/RedisClusterTest.java
0 → 100644
View file @
0d225da4
package
com
.
secoo
.
mall
.
redis
;
import
com.secoo.mall.redis.helper.RedisHelper
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.TimeUnit
;
/**
* Created by Administrator on 2018/1/15.
*/
//@ContextConfiguration({"classpath*:spring-jedis-cluster-config-sample.xml"})
@ContextConfiguration
({
"classpath*:spring-lettuce-cluster-config-sample.xml"
})
public
class
RedisClusterTest
extends
AbstractJUnit4SpringContextTests
{
@Resource
private
RedisHelper
redisClusterHelper
;
@Resource
private
PersonService
personService
;
@Test
public
void
testSet
()
throws
InterruptedException
{
redisClusterHelper
.
set
(
"aaa"
,
"bbb"
);
String
ret
=
redisClusterHelper
.
get
(
"aaa"
,
String
.
class
);
Assert
.
assertEquals
(
"bbb"
,
ret
);
redisClusterHelper
.
set
(
"aaa"
,
"ccc"
,
2
l
);
ret
=
redisClusterHelper
.
get
(
"aaa"
,
String
.
class
);
Assert
.
assertEquals
(
"ccc"
,
ret
);
Thread
.
sleep
(
3000
l
);
ret
=
redisClusterHelper
.
get
(
"aaa"
,
String
.
class
);
Assert
.
assertNull
(
ret
);
}
@Test
public
void
testSet2
()
throws
InterruptedException
{
//批量设置测试
Map
<
String
,
String
>
dtos1
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
dtos1
.
put
(
"testKey"
+
i
,
"testValue"
+
i
);
}
long
st
=
System
.
currentTimeMillis
();
redisClusterHelper
.
sets
(
dtos1
,
1000L
);
long
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时:"
+
(
ed
-
st
));
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
dtos1
.
put
(
"testKeyi"
+
i
,
"testValue"
+
i
);
}
st
=
System
.
currentTimeMillis
();
redisClusterHelper
.
sets
(
dtos1
,
1000L
);
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时:"
+
(
ed
-
st
));
List
<
String
>
list
=
redisClusterHelper
.
gets
(
new
ArrayList
<
String
>(
dtos1
.
keySet
()),
String
.
class
);
System
.
out
.
println
(
list
);
Map
<
String
,
String
>
dtos2
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
dtos2
.
put
(
"testKey2:"
+
i
,
"testValue2:"
+
i
);
}
st
=
System
.
currentTimeMillis
();
redisClusterHelper
.
pipelineSets
(
dtos2
,
1000L
);
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时2:"
+
(
ed
-
st
));
}
/**
* 测试多线程
*/
@Test
public
void
testThreads
()
throws
InterruptedException
{
ExecutorService
executorService
=
Executors
.
newCachedThreadPool
();
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
final
int
j
=
i
;
executorService
.
submit
(
new
Runnable
()
{
@Override
public
void
run
()
{
Map
<
String
,
String
>
dtos1
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
dtos1
.
put
(
"testKey"
+
j
+
":"
+
i
,
"testValue"
+
i
);
}
long
st
=
System
.
currentTimeMillis
();
redisClusterHelper
.
sets
(
dtos1
,
1000L
);
long
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时:"
+
j
+
":"
+
(
ed
-
st
));
}
});
}
Thread
.
sleep
(
5000L
);
for
(
int
i
=
20
;
i
<
40
;
i
++)
{
final
int
j
=
i
;
executorService
.
submit
(
new
Runnable
()
{
@Override
public
void
run
()
{
Map
<
String
,
String
>
dtos1
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
dtos1
.
put
(
"testKey"
+
j
+
":"
+
i
,
"testValue"
+
i
);
}
long
st
=
System
.
currentTimeMillis
();
redisClusterHelper
.
sets
(
dtos1
,
1000L
);
long
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时:"
+
j
+
":"
+
(
ed
-
st
));
}
});
}
Thread
.
sleep
(
5000L
);
}
@Test
public
void
testGet
()
{
Person
p
=
new
Person
();
p
.
setDeptName
(
"hhhhhh"
);
p
.
setOperDate
(
new
Date
());
redisClusterHelper
.
set
(
"zhangsan111"
,
p
);
Person
o
=
redisClusterHelper
.
get
(
"zhangsan111"
,
Person
.
class
);
Assert
.
assertEquals
(
"hhhhhh"
,
o
.
getDeptName
());
}
@Test
public
void
testGet2
()
throws
InterruptedException
{
//批量设置测试
Map
<
String
,
String
>
dtos2
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
dtos2
.
put
(
"testKey2:"
+
i
,
"testValue2:"
+
i
);
}
long
st
=
System
.
currentTimeMillis
();
redisClusterHelper
.
pipelineSets
(
dtos2
,
1000L
);
long
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时2:"
+
(
ed
-
st
));
st
=
System
.
currentTimeMillis
();
List
<
String
>
vList
=
redisClusterHelper
.
pipelineGets
(
new
ArrayList
<
String
>(
dtos2
.
keySet
()),
String
.
class
);
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时2:"
+
(
ed
-
st
));
System
.
out
.
println
(
vList
);
}
@Test
public
void
testH
()
{
Person
p
=
new
Person
();
p
.
setDeptName
(
"hhhhhh"
);
p
.
setOperDate
(
new
Date
());
redisClusterHelper
.
hSet
(
"hsetKey"
,
"f1"
,
p
);
Person
person
=
redisClusterHelper
.
hGet
(
"hsetKey"
,
"f1"
,
Person
.
class
);
Assert
.
assertEquals
(
"hhhhhh"
,
p
.
getDeptName
());
}
@Test
public
void
testAnn
()
{
Person
person
=
personService
.
get
(
1L
);
System
.
out
.
println
(
person
);
person
=
personService
.
get
(
1L
);
System
.
out
.
println
(
person
);
}
@Test
public
void
testIncr
()
{
redisClusterHelper
.
set
(
"incyKey"
,
1
);
System
.
out
.
println
(
redisClusterHelper
.
get
(
"incyKey"
,
Long
.
class
));
redisClusterHelper
.
incr
(
"incyKey"
,
1
);
System
.
out
.
println
(
redisClusterHelper
.
get
(
"incyKey"
,
Long
.
class
));
redisClusterHelper
.
incr
(
"incyKey"
,
10
);
System
.
out
.
println
(
redisClusterHelper
.
get
(
"incyKey"
,
Long
.
class
));
}
@Test
public
void
testTtl
()
throws
InterruptedException
{
redisClusterHelper
.
set
(
"incyKey"
,
1
,
100
);
System
.
out
.
println
(
redisClusterHelper
.
ttl
(
"incyKey"
,
TimeUnit
.
MILLISECONDS
));
Thread
.
sleep
(
444L
);
System
.
out
.
println
(
redisClusterHelper
.
ttl
(
"incyKey"
,
TimeUnit
.
MILLISECONDS
));
Thread
.
sleep
(
444L
);
System
.
out
.
println
(
redisClusterHelper
.
exists
(
"incyKey"
));
System
.
out
.
println
(
redisClusterHelper
.
exists
(
"incyKey111"
));
}
@Test
public
void
testHmset
()
{
Map
<
String
,
Integer
>
vv
=
new
HashMap
<>();
vv
.
put
(
"one"
,
1
);
vv
.
put
(
"two"
,
2
);
redisClusterHelper
.
hMSet
(
"hmsetNumKey"
,
vv
);
Map
<
String
,
Integer
>
ret
=
redisClusterHelper
.
hMGet
(
"hmsetNumKey"
,
new
String
[]{
"one"
,
"two"
},
Integer
.
class
);
System
.
out
.
println
(
ret
);
ret
=
redisClusterHelper
.
hGetAll
(
"hmsetNumKey"
,
String
.
class
,
Integer
.
class
);
System
.
out
.
println
(
ret
);
}
}
matrix-sample-redis/matrix-sample-redis-spring/src/main/java/com/secoo/mall/redis/RedisTest.java
View file @
0d225da4
...
...
@@ -7,199 +7,53 @@ import org.springframework.test.context.ContextConfiguration;
import
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.TimeUnit
;
import
javax.xml.crypto.Data
;
import
java.util.Date
;
/**
* Created by Administrator on 2018/1/15.
*/
//@ContextConfiguration({"classpath*:spring-jedis-
test
.xml"})
@ContextConfiguration
({
"classpath*:spring-lettuce-
test
.xml"
})
public
class
Redis
Cluster
Test
extends
AbstractJUnit4SpringContextTests
{
//@ContextConfiguration({"classpath*:spring-jedis-
alone-config-sample
.xml"})
@ContextConfiguration
({
"classpath*:spring-lettuce-
alone-config-sample
.xml"
})
public
class
RedisTest
extends
AbstractJUnit4SpringContextTests
{
@Resource
private
RedisHelper
redisClusterHelper
;
@Resource
private
PersonService
personService
;
private
RedisHelper
redisHelper
;
@Test
public
void
testSet
()
throws
InterruptedException
{
redis
Cluster
Helper
.
set
(
"aaa"
,
"bbb"
);
redisHelper
.
set
(
"aaa"
,
"bbb"
);
String
ret
=
redis
Cluster
Helper
.
get
(
"aaa"
,
String
.
class
);
String
ret
=
redisHelper
.
get
(
"aaa"
,
String
.
class
);
Assert
.
assertEquals
(
"bbb"
,
ret
);
redis
Cluster
Helper
.
set
(
"aaa"
,
"ccc"
,
2
l
);
ret
=
redis
Cluster
Helper
.
get
(
"aaa"
,
String
.
class
);
redisHelper
.
set
(
"aaa"
,
"ccc"
,
2
l
);
ret
=
redisHelper
.
get
(
"aaa"
,
String
.
class
);
Assert
.
assertEquals
(
"ccc"
,
ret
);
Thread
.
sleep
(
3000
l
);
ret
=
redis
Cluster
Helper
.
get
(
"aaa"
,
String
.
class
);
ret
=
redisHelper
.
get
(
"aaa"
,
String
.
class
);
Assert
.
assertNull
(
ret
);
//对实体对象操作
Person
person
=
new
Person
();
Date
date
=
new
Date
();
person
.
setOperDate
(
date
);
person
.
setLoginName
(
"李四"
);
redisHelper
.
set
(
"person03"
,
person
);
Assert
.
assertEquals
(
"李四"
,
redisHelper
.
get
(
"person03"
,
Person
.
class
).
getLoginName
());
Assert
.
assertEquals
(
date
,
person
.
getOperDate
());
}
@Test
public
void
testSet2
()
throws
InterruptedException
{
//批量设置测试
Map
<
String
,
String
>
dtos1
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
dtos1
.
put
(
"testKey"
+
i
,
"testValue"
+
i
);
}
long
st
=
System
.
currentTimeMillis
();
redisClusterHelper
.
sets
(
dtos1
,
1000L
);
long
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时:"
+
(
ed
-
st
));
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
dtos1
.
put
(
"testKeyi"
+
i
,
"testValue"
+
i
);
public
void
testIncr
()
{
redisHelper
.
set
(
"incyKey01"
,
1
);
redisHelper
.
incr
(
"incyKey01"
,
2
);
System
.
out
.
println
(
redisHelper
.
get
(
"incyKey01"
,
Long
.
class
));
}
st
=
System
.
currentTimeMillis
();
redisClusterHelper
.
sets
(
dtos1
,
1000L
);
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时:"
+
(
ed
-
st
));
List
<
String
>
list
=
redisClusterHelper
.
gets
(
new
ArrayList
<
String
>(
dtos1
.
keySet
()),
String
.
class
);
System
.
out
.
println
(
list
);
Map
<
String
,
String
>
dtos2
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
dtos2
.
put
(
"testKey2:"
+
i
,
"testValue2:"
+
i
);
}
st
=
System
.
currentTimeMillis
();
redisClusterHelper
.
pipelineSets
(
dtos2
,
1000L
);
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时2:"
+
(
ed
-
st
));
}
/**
*
测试多线程
*
其他方法使用详见 @com.secoo.mall.redis.RedisClusterTest
*/
@Test
public
void
testThreads
()
throws
InterruptedException
{
ExecutorService
executorService
=
Executors
.
newCachedThreadPool
();
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
final
int
j
=
i
;
executorService
.
submit
(
new
Runnable
()
{
@Override
public
void
run
()
{
Map
<
String
,
String
>
dtos1
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
dtos1
.
put
(
"testKey"
+
j
+
":"
+
i
,
"testValue"
+
i
);
}
long
st
=
System
.
currentTimeMillis
();
redisClusterHelper
.
sets
(
dtos1
,
1000L
);
long
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时:"
+
j
+
":"
+
(
ed
-
st
));
}
});
}
Thread
.
sleep
(
5000L
);
for
(
int
i
=
20
;
i
<
40
;
i
++)
{
final
int
j
=
i
;
executorService
.
submit
(
new
Runnable
()
{
@Override
public
void
run
()
{
Map
<
String
,
String
>
dtos1
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
dtos1
.
put
(
"testKey"
+
j
+
":"
+
i
,
"testValue"
+
i
);
}
long
st
=
System
.
currentTimeMillis
();
redisClusterHelper
.
sets
(
dtos1
,
1000L
);
long
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时:"
+
j
+
":"
+
(
ed
-
st
));
}
});
}
Thread
.
sleep
(
5000L
);
}
@Test
public
void
testGet
()
{
Person
p
=
new
Person
();
p
.
setDeptName
(
"hhhhhh"
);
p
.
setOperDate
(
new
Date
());
redisClusterHelper
.
set
(
"zhangsan111"
,
p
);
Person
o
=
redisClusterHelper
.
get
(
"zhangsan111"
,
Person
.
class
);
Assert
.
assertEquals
(
"hhhhhh"
,
o
.
getDeptName
());
}
@Test
public
void
testGet2
()
throws
InterruptedException
{
//批量设置测试
Map
<
String
,
String
>
dtos2
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
dtos2
.
put
(
"testKey2:"
+
i
,
"testValue2:"
+
i
);
}
long
st
=
System
.
currentTimeMillis
();
redisClusterHelper
.
pipelineSets
(
dtos2
,
1000L
);
long
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时2:"
+
(
ed
-
st
));
st
=
System
.
currentTimeMillis
();
List
<
String
>
vList
=
redisClusterHelper
.
pipelineGets
(
new
ArrayList
<
String
>(
dtos2
.
keySet
()),
String
.
class
);
ed
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"耗时2:"
+
(
ed
-
st
));
System
.
out
.
println
(
vList
);
}
@Test
public
void
testH
()
{
Person
p
=
new
Person
();
p
.
setDeptName
(
"hhhhhh"
);
p
.
setOperDate
(
new
Date
());
redisClusterHelper
.
hSet
(
"hsetKey"
,
"f1"
,
p
);
Person
person
=
redisClusterHelper
.
hGet
(
"hsetKey"
,
"f1"
,
Person
.
class
);
Assert
.
assertEquals
(
"hhhhhh"
,
p
.
getDeptName
());
}
@Test
public
void
testAnn
()
{
Person
person
=
personService
.
get
(
1L
);
System
.
out
.
println
(
person
);
person
=
personService
.
get
(
1L
);
System
.
out
.
println
(
person
);
}
@Test
public
void
testIncr
()
{
redisClusterHelper
.
set
(
"incyKey"
,
1
);
System
.
out
.
println
(
redisClusterHelper
.
get
(
"incyKey"
,
Long
.
class
));
redisClusterHelper
.
incr
(
"incyKey"
,
1
);
System
.
out
.
println
(
redisClusterHelper
.
get
(
"incyKey"
,
Long
.
class
));
redisClusterHelper
.
incr
(
"incyKey"
,
10
);
System
.
out
.
println
(
redisClusterHelper
.
get
(
"incyKey"
,
Long
.
class
));
}
@Test
public
void
testTtl
()
throws
InterruptedException
{
redisClusterHelper
.
set
(
"incyKey"
,
1
,
100
);
System
.
out
.
println
(
redisClusterHelper
.
ttl
(
"incyKey"
,
TimeUnit
.
MILLISECONDS
));
Thread
.
sleep
(
444L
);
System
.
out
.
println
(
redisClusterHelper
.
ttl
(
"incyKey"
,
TimeUnit
.
MILLISECONDS
));
Thread
.
sleep
(
444L
);
System
.
out
.
println
(
redisClusterHelper
.
exists
(
"incyKey"
));
System
.
out
.
println
(
redisClusterHelper
.
exists
(
"incyKey111"
));
}
@Test
public
void
testHmset
()
{
Map
<
String
,
Integer
>
vv
=
new
HashMap
<>();
vv
.
put
(
"one"
,
1
);
vv
.
put
(
"two"
,
2
);
redisClusterHelper
.
hMSet
(
"hmsetNumKey"
,
vv
);
Map
<
String
,
Integer
>
ret
=
redisClusterHelper
.
hMGet
(
"hmsetNumKey"
,
new
String
[]{
"one"
,
"two"
},
Integer
.
class
);
System
.
out
.
println
(
ret
);
ret
=
redisClusterHelper
.
hGetAll
(
"hmsetNumKey"
,
String
.
class
,
Integer
.
class
);
System
.
out
.
println
(
ret
);
}
}
matrix-sample-redis/matrix-sample-redis-spring/src/main/resources/redis-cluster.properties
View file @
0d225da4
redis.maxRedirects
=
5
redis.host1
=
10.185.240.142
redis.host1
=
dev01-rediscluster01.secoolocal.com
redis.port1
=
7001
redis.host2
=
10.185.240.142
redis.host2
=
dev01-rediscluster01.secoolocal.com
redis.port2
=
7002
redis.host3
=
10.185.240.142
redis.port3
=
700
3
redis.host4
=
10.185.240.142
redis.port4
=
700
4
redis.host5
=
10.185.240.142
redis.port5
=
700
5
redis.host6
=
10.185.240.142
redis.port6
=
700
6
redis.host3
=
dev01-rediscluster02.secoolocal.com
redis.port3
=
700
1
redis.host4
=
dev01-rediscluster02.secoolocal.com
redis.port4
=
700
2
redis.host5
=
dev01-rediscluster03.secoolocal.com
redis.port5
=
700
1
redis.host6
=
dev01-rediscluster03.secoolocal.com
redis.port6
=
700
2
# connnet pool
redis.maxIdle
=
50
redis.maxTotal
=
100
...
...
matrix-sample-redis/matrix-sample-redis-spring/src/main/resources/spring-jedis-alone-config-sample.xml
View file @
0d225da4
<?xml version="1.0" encoding="utf-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx=
"http://www.springframework.org/schema/tx"
xmlns:aop=
"http://www.springframework.org/schema/aop"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:p=
"http://www.springframework.org/schema/p"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-txs-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd"
>
<context:property-placeholder
ignore-unresolvable=
"true"
location=
"classpath:redis-cluster.properties"
/>
<context:component-scan
base-package=
"com.secooframework"
></context:component-scan>
<bean
id=
"redisClusterConfiguration"
class=
"org.springframework.data.redis.connection.RedisClusterConfiguration"
>
<property
name=
"maxRedirects"
value=
"${redis.maxRedirects}"
></property>
<property
name=
"clusterNodes"
>
<set>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host1}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port1}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host2}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port2}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host3}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port3}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host4}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port4}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host5}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port5}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host6}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port6}"
></constructor-arg>
</bean>
</set>
</property>
<context:component-scan
base-package=
"com.secoo.mall"
></context:component-scan>
<!--单主机配置-->
<bean
id=
"redisAloneConfiguration"
class=
"org.springframework.data.redis.connection.RedisStandaloneConfiguration"
>
<property
name=
"hostName"
value=
"127.0.0.1"
/>
<property
name=
"port"
value=
"6379"
/>
</bean>
<bean
id=
"jedisPoolConfig"
class=
"redis.clients.jedis.JedisPoolConfig"
>
<property
name=
"maxIdle"
value=
"${redis.maxIdle}"
/>
<property
name=
"maxTotal"
value=
"${redis.maxTotal}"
/>
...
...
@@ -60,14 +30,19 @@
<bean
id=
"jeidsConnectionFactory"
class=
"org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
>
<constructor-arg
ref=
"redisCluster
Configuration"
/>
<constructor-arg
ref=
"redisAlone
Configuration"
/>
<constructor-arg
ref=
"jedisPoolConfig"
/>
</bean>
<bean
id=
"redisTemplate"
class=
"org.springframework.data.redis.core.RedisTemplate"
>
<property
name=
"connectionFactory"
ref=
"jeidsConnectionFactory"
/>
<!-- 序列化方式 key/hashKey采用StringRedisSerializer -->
<property
name=
"keySerializer"
>
</bean>
<bean
id=
"redisHelper"
class=
"com.secoo.mall.redis.helper.RedisHelper"
>
<constructor-arg
name=
"redisTemplate"
ref=
"redisTemplate"
/>
<!-- 序列化方式 key/hashKey采用StringRedisSerializer-->
<!--<property name="keySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
...
...
@@ -82,9 +57,7 @@
<property name="hashValueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property
>
</property>--
>
</bean>
<bean
id=
"secooRedisTemplate"
class=
"com.secooframework.redis.SecooRedisTemplate"
/>
</beans>
matrix-sample-redis/matrix-sample-redis-spring/src/main/resources/spring-jedis-cluster-config-sample.xml
View file @
0d225da4
...
...
@@ -17,7 +17,7 @@
<context:property-placeholder
ignore-unresolvable=
"true"
location=
"classpath:redis-cluster.properties"
/>
<context:component-scan
base-package=
"com.secoo
framework
"
></context:component-scan>
<context:component-scan
base-package=
"com.secoo
.mall
"
></context:component-scan>
<bean
id=
"redisClusterConfiguration"
class=
"org.springframework.data.redis.connection.RedisClusterConfiguration"
>
...
...
@@ -64,10 +64,14 @@
<constructor-arg
ref=
"jedisPoolConfig"
/>
</bean>
<bean
id=
"redisTemplate"
class=
"org.springframework.data.redis.core.RedisTemplate"
>
<bean
id=
"redis
Cluster
Template"
class=
"org.springframework.data.redis.core.RedisTemplate"
>
<property
name=
"connectionFactory"
ref=
"jeidsConnectionFactory"
/>
</bean>
<bean
id=
"secooRedisTemplate"
class=
"com.secoo.mall.redis.helper.RedisHelper"
>
<constructor-arg
name=
"redisTemplate"
ref=
"redisClusterTemplate"
/>
<!-- 序列化方式 key/hashKey采用StringRedisSerializer -->
<property
name=
"keySerializer"
>
<!--
<property name="keySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
...
...
@@ -82,9 +86,7 @@
<property name="hashValueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
</property>
-->
</bean>
<bean
id=
"secooRedisTemplate"
class=
"com.secooframework.redis.SecooRedisTemplate"
/>
</beans>
matrix-sample-redis/matrix-sample-redis-spring/src/main/resources/spring-lettuce-alone-config-sample.xml
View file @
0d225da4
<?xml version="1.0" encoding="utf-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx=
"http://www.springframework.org/schema/tx"
xmlns:aop=
"http://www.springframework.org/schema/aop"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:p=
"http://www.springframework.org/schema/p"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-txs-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context
...
...
@@ -21,65 +19,23 @@
<aop:config
proxy-target-class=
"true"
></aop:config>
<aop:aspectj-autoproxy/>
<bean
id=
"redisClusterConfiguration"
class=
"org.springframework.data.redis.connection.RedisClusterConfiguration"
>
<property
name=
"maxRedirects"
value=
"${redis.maxRedirects}"
></property>
<property
name=
"clusterNodes"
>
<set>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host1}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port1}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host2}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port2}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host3}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port3}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host4}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port4}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host5}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port5}"
></constructor-arg>
<!--单主机配置-->
<bean
id=
"redisAloneConfiguration"
class=
"org.springframework.data.redis.connection.RedisStandaloneConfiguration"
>
<property
name=
"hostName"
value=
"127.0.0.1"
/>
<property
name=
"port"
value=
"6379"
/>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host6}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port6}"
></constructor-arg>
</bean>
</set>
</property>
</bean>
<!--<bean id="clientResources" class="com.lambdaworks.redis.resource.DefaultClientResources"-->
<!--factory-method="create">-->
<!--</bean>-->
<bean
id=
"lettuceConnectionFactory"
class=
"org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory"
>
<constructor-arg
ref=
"redisClusterConfiguration"
/>
<!--<property name="clientResources" ref="clientResources"/>-->
</bean>
<constructor-arg
ref=
"redisAloneConfiguration"
/>
<!--可以注入一个mapper,默认的序列化会序列化类名-->
<!--ObjectMapper mapper = new ObjectMapper();-->
<!--mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);-->
<!--//日期格式-->
<!--mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));-->
<!--//null不序列化 减小报文大小-->
<!--mapper.setSerializationInclusion(Include.NON_NULL);-->
</bean>
<bean
id=
"redisCluser
Template"
class=
"org.springframework.data.redis.core.RedisTemplate"
>
<bean
id=
"rediredisAloneConfiguration
Template"
class=
"org.springframework.data.redis.core.RedisTemplate"
>
<property
name=
"connectionFactory"
ref=
"lettuceConnectionFactory"
/>
<!-- 序列化方式 key/hashKey采用StringRedisSerializer -->
<property
name=
"keySerializer"
>
<bean
class=
"org.springframework.data.redis.serializer.StringRedisSerializer"
/>
<bean
class=
"org.springframework.data.redis.serializer.StringRedisSerializer"
/>
</property>
<property
name=
"hashKeySerializer"
>
<bean
...
...
@@ -93,10 +49,27 @@
<bean
class=
"org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"
/>
</property>
</bean>
<bean
id=
"redisClusterHelper"
class=
"com.secoo.mall.redis.helper.RedisHelper"
>
<constructor-arg
name=
"redisTemplate"
ref=
"redisCluserTemplate"
/>
<bean
id=
"redisHelper"
class=
"com.secoo.mall.redis.helper.RedisHelper"
>
<constructor-arg
name=
"redisTemplate"
ref=
"rediredisAloneConfigurationTemplate"
/>
<!-- 序列化方式 key/hashKey采用StringRedisSerializer ,不指定可以使用默认的-->
<!-- <property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>-->
</bean>
...
...
matrix-sample-redis/matrix-sample-redis-spring/src/main/resources/spring-lettuce-cluster-config-sample.xml
0 → 100644
View file @
0d225da4
<?xml version="1.0" encoding="utf-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx=
"http://www.springframework.org/schema/tx"
xmlns:aop=
"http://www.springframework.org/schema/aop"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:p=
"http://www.springframework.org/schema/p"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-txs-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd"
>
<context:property-placeholder
ignore-unresolvable=
"true"
location=
"classpath:redis-cluster.properties"
/>
<context:component-scan
base-package=
"com.secoo.mall"
></context:component-scan>
<aop:config
proxy-target-class=
"true"
></aop:config>
<aop:aspectj-autoproxy/>
<bean
id=
"redisClusterConfiguration"
class=
"org.springframework.data.redis.connection.RedisClusterConfiguration"
>
<property
name=
"maxRedirects"
value=
"${redis.maxRedirects}"
></property>
<property
name=
"clusterNodes"
>
<set>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host1}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port1}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host2}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port2}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host3}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port3}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host4}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port4}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host5}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port5}"
></constructor-arg>
</bean>
<bean
class=
"org.springframework.data.redis.connection.RedisClusterNode"
>
<constructor-arg
name=
"host"
value=
"${redis.host6}"
></constructor-arg>
<constructor-arg
name=
"port"
value=
"${redis.port6}"
></constructor-arg>
</bean>
</set>
</property>
</bean>
<!--<bean id="clientResources" class="com.lambdaworks.redis.resource.DefaultClientResources"-->
<!--factory-method="create">-->
<!--</bean>-->
<bean
id=
"lettuceConnectionFactory"
class=
"org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory"
>
<constructor-arg
ref=
"redisClusterConfiguration"
/>
<!--<property name="clientResources" ref="clientResources"/>-->
</bean>
<!--可以注入一个mapper,默认的序列化会序列化类名-->
<!--ObjectMapper mapper = new ObjectMapper();-->
<!--mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);-->
<!--//日期格式-->
<!--mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));-->
<!--//null不序列化 减小报文大小-->
<!--mapper.setSerializationInclusion(Include.NON_NULL);-->
<bean
id=
"redisCluserTemplate"
class=
"org.springframework.data.redis.core.RedisTemplate"
>
<property
name=
"connectionFactory"
ref=
"lettuceConnectionFactory"
/>
</bean>
<bean
id=
"redisClusterHelper"
class=
"com.secoo.mall.redis.helper.RedisHelper"
>
<constructor-arg
name=
"redisTemplate"
ref=
"redisCluserTemplate"
/>
<!-- 序列化方式 key/hashKey采用StringRedisSerializer ,也可以使用默认的-->
<!--<property name="keySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>-->
</bean>
</beans>
matrix-sample-redis/matrix-sample-redis-starter/pom.xml
View file @
0d225da4
...
...
@@ -10,6 +10,20 @@
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
matrix-sample-redis-starter
</artifactId>
<dependencies>
<dependency>
<groupId>
com.secoo.mall
</groupId>
<artifactId>
matrix-sample-redis-biz
</artifactId>
</dependency>
<dependency>
<groupId>
com.secoo.mall
</groupId>
<artifactId>
matrix-datahelper-redis-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
matrix-sample-redis/matrix-sample-redis-starter/src/main/java/com/secoo/mall/redis/RedisSampleApplication.java
View file @
0d225da4
package
com
.
secoo
.
mall
.
redis
;
public
class
RedisSampleApplication
{
import
com.secoo.mall.redis.helper.RedisHelper
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
javax.annotation.Resource
;
import
java.util.Date
;
@SpringBootApplication
public
class
RedisSampleApplication
implements
ApplicationRunner
{
@Resource
private
RedisHelper
redisHelper
;
@Resource
private
RedisHelper
productRedisHelper
;
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
RedisSampleApplication
.
class
).
run
(
args
);
}
@Override
public
void
run
(
ApplicationArguments
args
)
throws
Exception
{
redisHelper
.
set
(
"key01"
,
"word"
);
String
key01
=
redisHelper
.
get
(
"key01"
,
String
.
class
);
Person
person
=
new
Person
();
person
.
setId
(
2L
);
// person.setDeptName("技术部");
person
.
setLoginName
(
"zhangsan"
);
person
.
setOperDate
(
new
Date
());
redisHelper
.
set
(
"person05"
,
person
);
//1.通过测试,Fastjson,对象缺少属性后支持序列化
System
.
out
.
println
(
"person05::"
+
redisHelper
.
get
(
"person05"
,
Person
.
class
).
getLoginName
());
productRedisHelper
.
set
(
"p:01"
,
"帽子"
);
System
.
out
.
println
(
"p:01="
+
productRedisHelper
.
get
(
"p:01"
,
String
.
class
));
}
}
matrix-sample-redis/matrix-sample-redis-starter/src/main/java/com/secoo/mall/redis/config/MuliRedisConfig.java
View file @
0d225da4
package
com
.
secoo
.
mall
.
redis
.
config
;
import
com.secoo.mall.redis.helper.RedisHelper
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
/**
* 多数据源配置
*/
@Configuration
@ConfigurationProperties
(
prefix
=
"redis.custom"
)
@Data
public
class
MuliRedisConfig
{
public
String
host
;
public
Integer
port
;
/**
* 仅仅提供简单配置demo
*
* @return
*/
@Bean
public
LettuceConnectionFactory
productConnectionFactory
()
{
LettuceConnectionFactory
connectionFactory
=
new
LettuceConnectionFactory
(
host
,
port
);
return
connectionFactory
;
}
@Bean
public
RedisTemplate
productRedisTemplate
(
LettuceConnectionFactory
productConnectionFactory
){
RedisTemplate
redisTemplate
=
new
RedisTemplate
();
redisTemplate
.
setConnectionFactory
(
productConnectionFactory
);
return
redisTemplate
;
}
@Bean
(
"productRedisHelper"
)
public
RedisHelper
productRedisHelper
(
RedisTemplate
productRedisTemplate
)
{
return
new
RedisHelper
(
productRedisTemplate
);
}
}
matrix-sample-redis/matrix-sample-redis-starter/src/main/resources/application.yml
View file @
0d225da4
spring
:
redis
:
cluster
:
nodes
:
dev01-rediscluster01.secoolocal.com:7001,dev01-rediscluster01.secoolocal.com:7002,dev01-rediscluster02.secoolocal.com:7001,dev01-rediscluster02.secoolocal.com:7002,dev01-rediscluster03.secoolocal.com:7001,dev01-rediscluster03.secoolocal.com:7002
timeout
:
10000
# host: localhost
redis
:
custom
:
host
:
localhost
port
:
6379
\ No newline at end of file
matrix-sample-redis/pom.xml
View file @
0d225da4
...
...
@@ -14,7 +14,38 @@
<modules>
<module>
matrix-sample-redis-starter
</module>
<module>
matrix-sample-redis-biz
</module>
<module>
matrix-sample-redis-spring
</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
com.secoo.mall
</groupId>
<artifactId>
matrix-sample-redis-biz
</artifactId>
<version>
1.3.2.RELEASE
</version>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
<version>
3.2.0
</version>
</dependency>
<!-- 推荐使用 lettuce -->
<dependency>
<groupId>
io.lettuce
</groupId>
<artifactId>
lettuce-core
</artifactId>
<version>
5.2.2.RELEASE
</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>
com.secoo.mall
</groupId>
<artifactId>
common-util
</artifactId>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-databind
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
matrix-sample-rocketmq/matrix-sample-rocketmq-spring/pom.xml
View file @
0d225da4
...
...
@@ -20,6 +20,16 @@
<artifactId>
matrix-sample-rocketmq-biz
</artifactId>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
biz.paluch.redis
</groupId>
<artifactId>
lettuce
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
</dependency>
...
...
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