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
841d6657
Commit
841d6657
authored
Dec 11, 2019
by
QIANGLU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加redis使用demo
parent
a551176b
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
180 additions
and
88 deletions
+180
-88
pom.xml
spring-boot-agent-demo/pom.xml
+1
-1
pom.xml
spring-boot-agent/pom.xml
+1
-1
pom.xml
spring-boot-pure/pom.xml
+1
-1
pom.xml
spring-boot-redis/pom.xml
+70
-0
RedisStartup.java
spring-boot-redis/src/main/java/com/matrix/redis/RedisStartup.java
+18
-0
RedisDemoService.java
spring-boot-redis/src/main/java/com/matrix/redis/demo/RedisDemoService.java
+68
-0
application.yml
spring-boot-redis/src/main/resources/application.yml
+18
-0
RcoketStartup.java
spring-boot-rocketmq/src/main/java/com/matrix/pure/RcoketStartup.java
+1
-1
ConsumerListener.java
spring-boot-rocketmq/src/main/java/com/matrix/pure/rocketmq/ConsumerListener.java
+1
-1
SendRocketDemo.java
spring-boot-rocketmq/src/main/java/com/matrix/pure/rocketmq/SendRocketDemo.java
+1
-1
NettyClient.java
spring-boot-rocketmq/src/main/java/com/matrix/pure/tcp/NettyClient.java
+0
-27
NettyServer.java
spring-boot-rocketmq/src/main/java/com/matrix/pure/tcp/NettyServer.java
+0
-55
No files found.
spring-boot-agent-demo/pom.xml
View file @
841d6657
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
<parent>
<parent>
<artifactId>
matrix
</artifactId>
<artifactId>
matrix
</artifactId>
<groupId>
com.secoo.mall
</groupId>
<groupId>
com.secoo.mall
</groupId>
<version>
1.1.
0
.RELEASE
</version>
<version>
1.1.
8
.RELEASE
</version>
</parent>
</parent>
<dependencies>
<dependencies>
<dependency>
<dependency>
...
...
spring-boot-agent/pom.xml
View file @
841d6657
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
<parent>
<parent>
<artifactId>
matrix
</artifactId>
<artifactId>
matrix
</artifactId>
<groupId>
com.secoo.mall
</groupId>
<groupId>
com.secoo.mall
</groupId>
<version>
1.
0.11
.RELEASE
</version>
<version>
1.
1.8
.RELEASE
</version>
</parent>
</parent>
<properties>
<properties>
...
...
spring-boot-pure/pom.xml
View file @
841d6657
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
<parent>
<parent>
<artifactId>
matrix
</artifactId>
<artifactId>
matrix
</artifactId>
<groupId>
com.secoo.mall
</groupId>
<groupId>
com.secoo.mall
</groupId>
<version>
1.
0.11
.RELEASE
</version>
<version>
1.
1.8
.RELEASE
</version>
</parent>
</parent>
<properties>
<properties>
...
...
spring-boot-redis/pom.xml
0 → 100644
View file @
841d6657
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.nova
</groupId>
<artifactId>
spring-boot-redis
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<parent>
<artifactId>
matrix
</artifactId>
<groupId>
com.secoo.mall
</groupId>
<version>
1.1.8.RELEASE
</version>
</parent>
<properties>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.secoo.mall
</groupId>
<artifactId>
logger-starter
</artifactId>
</dependency>
<dependency>
<groupId>
com.secoo.mall
</groupId>
<artifactId>
redis-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-autoconfigure
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
\ No newline at end of file
spring-boot-redis/src/main/java/com/matrix/redis/RedisStartup.java
0 → 100755
View file @
841d6657
package
com
.
matrix
.
redis
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
/**
* @author qianglu
*/
@SpringBootApplication
public
class
RedisStartup
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
RedisStartup
.
class
,
args
);
}
}
spring-boot-redis/src/main/java/com/matrix/redis/demo/RedisDemoService.java
0 → 100644
View file @
841d6657
package
com
.
matrix
.
redis
;
import
com.secoo.mall.redis.utils.MatrixRedisClusterUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
javax.websocket.SendResult
;
import
java.util.Set
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledFuture
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
/**
* @ClassName RedisDemoService
* @Author QIANGLU
* @Date 2019/12/11 3:45 下午
* @Version 1.0
*/
@Component
public
class
RedisDemoService
implements
Runnable
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
RedisDemoService
.
class
);
private
ScheduledFuture
<?>
scheduledFuture
;
private
volatile
AtomicInteger
count
=
new
AtomicInteger
();
public
RedisDemoService
()
{
scheduledFuture
=
Executors
.
newSingleThreadScheduledExecutor
().
scheduleAtFixedRate
(
this
,
0
,
1
,
TimeUnit
.
SECONDS
);
}
@Override
public
void
run
()
{
try
{
//存入Redis
MatrixRedisClusterUtils
.
opsForHash
().
put
(
"test_hashs"
,
"hash"
,
count
.
incrementAndGet
()+
"_hash"
);
logger
.
info
(
"存入Redis Hash 数据 key:{},val:{}"
,
"test_hashs_t1"
,
count
.
get
());
//set
MatrixRedisClusterUtils
.
opsForSet
().
add
(
"test_sets"
,
count
.
get
()
+
"_set"
);
logger
.
info
(
"存入Redis Set 数据 key:{},val:{}"
,
"test_sets"
,
count
.
get
());
MatrixRedisClusterUtils
.
opsForValue
().
set
(
"test_string"
,
count
.
get
()
+
"_string"
);
logger
.
info
(
"存入Redis Value 数据 key:{},val:{}"
,
"test_string"
,
count
.
get
());
//更多方法请查看 MatrixRedisClusterUtils
//取出
Object
obj
=
MatrixRedisClusterUtils
.
opsForHash
().
get
(
"test_hashs"
,
"hash"
);
logger
.
info
(
"取出Redis Hash 数据 key:{},val:{}"
,
"test_hashs"
,
obj
);
//set
Set
<
String
>
sets
=
MatrixRedisClusterUtils
.
opsForSet
().
members
(
"test_set"
);
logger
.
info
(
"取出Redis Set 数据 key:{},size:{}"
,
"test_set"
,
sets
.
size
());
String
val
=
MatrixRedisClusterUtils
.
opsForValue
().
get
(
"test_string"
);
logger
.
info
(
"取出Redis Set 数据 key:{},val:{}"
,
"test_string"
,
val
);
System
.
out
.
println
(
"==========================================="
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
}
spring-boot-redis/src/main/resources/application.yml
0 → 100644
View file @
841d6657
server
:
port
:
6080
spring
:
application
:
name
:
learn-redis
redis
:
# 配置可放入Apollo
host
:
10.0.253.9
#单机模式下使用此配置
# cluster: 集群模式下打开此注解
# nodes: 192.168.xx.4:7000,192.168.xx.14:7002,192.168.xx.18:7004
# max-redirects: 6
lettuce
:
pool
:
max-active
:
8
# 连接池最大连接数(使用负值表示没有限制)
max-idle
:
8
# 连接池中的最大空闲连接
min-idle
:
8
# 连接池中的最小空闲连接
max-wait
:
2000
# 连接池最大阻塞等待时间(使用负值表示没有限制)
timeout
:
2000
# 连接超时时间(毫秒)
spring-boot-rocketmq/src/main/java/com/matrix/pure/RcoketStartup.java
View file @
841d6657
package
com
.
matrix
.
pure
;
package
com
.
matrix
.
redis
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
...
spring-boot-rocketmq/src/main/java/com/matrix/pure/rocketmq/ConsumerListener.java
View file @
841d6657
package
com
.
matrix
.
pure
.
rocketmq
;
package
com
.
matrix
.
redis
.
rocketmq
;
import
org.apache.rocketmq.spring.annotation.RocketMQMessageListener
;
import
org.apache.rocketmq.spring.annotation.RocketMQMessageListener
;
import
org.apache.rocketmq.spring.core.RocketMQListener
;
import
org.apache.rocketmq.spring.core.RocketMQListener
;
...
...
spring-boot-rocketmq/src/main/java/com/matrix/pure/rocketmq/SendRocketDemo.java
View file @
841d6657
package
com
.
matrix
.
pure
.
rocketmq
;
package
com
.
matrix
.
redis
.
rocketmq
;
import
org.apache.rocketmq.client.producer.SendResult
;
import
org.apache.rocketmq.client.producer.SendResult
;
import
org.apache.rocketmq.common.message.Message
;
import
org.apache.rocketmq.common.message.Message
;
...
...
spring-boot-rocketmq/src/main/java/com/matrix/pure/tcp/NettyClient.java
deleted
100644 → 0
View file @
a551176b
package
com
.
matrix
.
pure
.
tcp
;
import
java.io.IOException
;
import
java.net.InetSocketAddress
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.SocketChannel
;
/**
* @ClassName NettyServer
* @Author QIANGLU
* @Date 2019/12/3 11:31 下午
* @Version 1.0
*/
public
class
NettyClient
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
SocketChannel
socketChannel
=
SocketChannel
.
open
();
socketChannel
.
bind
(
new
InetSocketAddress
(
"localhost"
,
9999
));
ByteBuffer
byteBuffer
=
ByteBuffer
.
allocate
(
1024
);
byteBuffer
.
put
(
"this is test "
.
getBytes
());
byteBuffer
.
flip
();
while
(
byteBuffer
.
hasRemaining
()){
socketChannel
.
write
(
byteBuffer
);
}
}
}
spring-boot-rocketmq/src/main/java/com/matrix/pure/tcp/NettyServer.java
deleted
100644 → 0
View file @
a551176b
package
com
.
matrix
.
pure
.
tcp
;
import
java.io.IOException
;
import
java.net.InetSocketAddress
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.SelectionKey
;
import
java.nio.channels.Selector
;
import
java.nio.channels.ServerSocketChannel
;
import
java.nio.channels.SocketChannel
;
import
java.util.Iterator
;
/**
* @ClassName NettyServer
* @Author QIANGLU
* @Date 2019/12/3 11:31 下午
* @Version 1.0
*/
public
class
NettyServer
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
Selector
selector
=
Selector
.
open
();
ServerSocketChannel
socketChannel
=
ServerSocketChannel
.
open
();
socketChannel
.
bind
(
new
InetSocketAddress
(
"loclhost"
,
9999
));
socketChannel
.
configureBlocking
(
false
);
socketChannel
.
register
(
selector
,
SelectionKey
.
OP_ACCEPT
);
while
(
true
)
{
selector
.
select
();
Iterator
<
SelectionKey
>
selectorIterator
=
selector
.
selectedKeys
().
iterator
();
while
(
selectorIterator
.
hasNext
()){
SelectionKey
selectionKey
=
selectorIterator
.
next
();
if
(
selectionKey
.
isAcceptable
()){
SocketChannel
channel
=
socketChannel
.
accept
();
channel
.
configureBlocking
(
false
);
channel
.
register
(
selector
,
SelectionKey
.
OP_READ
,
ByteBuffer
.
allocate
(
1024
));
}
if
(
selectionKey
.
isReadable
()){
}
}
//
SocketChannel
socketChannel1
=
socketChannel
.
accept
();
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
1024
);
int
reder
=
socketChannel1
.
read
(
buffer
);
if
(
reder
>
0
)
{
buffer
.
flip
();
byte
[]
bytes
=
new
byte
[
buffer
.
remaining
()];
buffer
.
get
(
bytes
);
String
body
=
new
String
(
bytes
,
"UTF-8"
);
System
.
out
.
println
(
"server 收到:"
+
body
);
}
}
}
}
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