Skip to content

Commit a71c299

Browse files
committed
redis 简单使用
1 parent c963da9 commit a71c299

File tree

27 files changed

+932
-49
lines changed

27 files changed

+932
-49
lines changed

spring-boot-15-Redis/README.md

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
1-
----
2-
## [spring-boot-3-logs spring boot 整合多个日志框架](https://github.com/timebusker/spring-boot/tree/master/spring-boot-3-logs/)
3-
4-
## 良好日志架构:SLF4J + Log4j/Log4j2/Logback
5-
6-
## 日志架构性能比较:日志性能比较:Log4j < Logback < Log4j2
7-
8-
### 项目阐述——spring boot 整合多个日志框架:Log4j、Log4j2、Logback
9-
![image](https://github.com/timebusker/spring-boot/raw/master/static/spring-boot-3-logs/logging.png?raw=true)
10-
![image](https://github.com/timebusker/spring-boot/raw/master/static/spring-boot-3-logs/SLF4J.png?raw=true)
11-
12-
+ #### [spring-boot 整合Log4j](https://github.com/timebusker/spring-boot/tree/master/spring-boot-3-logs/spring-boot-3-logs-Log4j/)
13-
* spring-boot 1.4.x.RELEASE 将不再支持
14-
* Log4j配置说明
15-
* Log4j配置信息
16-
* 配置多环境不同日志级别
17-
18-
+ #### [spring-boot 整合Log4j2](https://github.com/timebusker/spring-boot/tree/master/spring-boot-3-logs/spring-boot-3-logs-Log4j2/)
19-
* Log4j2配置说明
20-
* Log4j2配置信息
21-
* 配置多环境不同日志级别
22-
23-
+ #### [spring-boot 整合Logback](https://github.com/timebusker/spring-boot/tree/master/spring-boot-3-logs/spring-boot-3-logs-Logback/)
24-
* spring boot 1.4.X默认日志框架为 SLF4J+Logback
25-
* Logback 配置信息
26-
* 配置多环境不同日志级别
27-
28-
----
1+
### [Redis使用实践](https://github.com/timebusker/spring-boot/tree/master/spring-boot-15-Redis/)
2+
3+
### Redis简介
4+
- Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库。它可以用作数据库、缓存和消息中间件。 它支持多种类型的数据结构,如 字符串(strings), 散列(hashes), 列表(lists), 集合(sets), 有序集合(sorted sets) 与范围查询, bitmaps, hyperloglogs 和 地理空间(geospatial) 索引半径查询。 Redis 内置了 复制(replication),LUA脚本(Lua scripting), LRU驱动事件(LRU eviction),事务(transactions) 和不同级别的 磁盘持久化(persistence), 并通过 Redis哨兵(Sentinel)和自动 分区(Cluster)提供高可用性(high availability)。
5+
- **Redis 优势:**
6+
- 性能极高 – Redis能读的速度是110000次/s,写的速度是81000次/s
7+
- 丰富的数据类型 – Redis支持二进制案例的 Strings, Lists, Hashes, Sets 及 Ordered Sets 数据类型操作
8+
- 原子 – Redis的所有操作都是原子性的,同时Redis还支持对几个操作全并后的原子性执行
9+
- 丰富的特性 – Redis还支持 publish/subscribe, 通知, key 过期等等特性
10+
11+
- ##### [Redis简单使用](https://github.com/timebusker/spring-boot/tree/master/spring-boot-15-Redis/spring-boot-15-Redis-sample/)
12+
13+
- ##### [Redis作Cache](https://github.com/timebusker/spring-boot/tree/master/spring-boot-15-Redis/spring-boot-15-Redis-cache)
14+
15+
- ##### [Redis作Session](https://github.com/timebusker/spring-boot/tree/master/spring-boot-15-Redis/spring-boot-15-Redis-session)
16+
17+
- ##### [Redis作MQ](https://github.com/timebusker/spring-boot/tree/master/spring-boot-15-Redis/spring-boot-15-Redis-mq)
18+
19+
- ##### [Redis作集群](https://github.com/timebusker/spring-boot/tree/master/spring-boot-15-Redis/spring-boot-15-Redis-cluster)
20+
21+
2922

3023
### 相关文章
31-
- [混乱的 Java 日志体系](http://note.youdao.com/noteshare?id=8ee5d113de15c2bee1d36be76dddd717)
32-
- [为什么要使用SLF4J而不是Log4J](http://note.youdao.com/noteshare?id=f47db61d63b5254c76cd9404ef5c83e6)
33-
- [在 Web 应用中增加用户跟踪功能——学习在多线程环境下 Apache Log4j 的 NDC和MDC 开发](http://note.youdao.com/noteshare?id=9e15b0c68bedf37147965b213203de99)
34-
- [log4j+logback+slf4j+commons-logging的关系与调试](http://www.cnblogs.com/zhuawang/p/3999235.html)
24+
25+
- [Redis 教程](http://www.runoob.com/redis/redis-intro.html)
26+
- [Spring Boot with Redis](http://www.jianshu.com/p/a2ab17707eff)
27+
- [Spring Boot中使用Redis数据库](http://blog.didispace.com/springbootredis/)

spring-boot-15-Redis/pom.xml

Lines changed: 108 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,109 @@
1-
<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">
2-
<modelVersion>4.0.0</modelVersion>
3-
<parent>
4-
<groupId>cn.timebusker</groupId>
5-
<artifactId>spring-boot</artifactId>
6-
<version>2.0.0</version>
7-
</parent>
8-
<artifactId>spring-boot-15-Redis</artifactId>
9-
<packaging>pom</packaging>
10-
<name>spring-boot-15-Redis</name>
11-
<description>spring boot redis 使用总结:消息队列、缓存</description>
12-
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>cn.timebusker</groupId>
7+
<artifactId>spring-boot</artifactId>
8+
<version>2.0.0</version>
9+
</parent>
10+
<artifactId>spring-boot-15-Redis</artifactId>
11+
<packaging>pom</packaging>
12+
<name>spring-boot-15-Redis</name>
13+
<description>spring boot redis 使用总结:消息队列�?�缓�?</description>
14+
15+
<modules>
16+
<module>spring-boot-15-Redis-sample</module>
17+
<module>spring-boot-15-Redis-cache</module>
18+
<module>spring-boot-15-Redis-mq</module>
19+
</modules>
20+
21+
<dependencies>
22+
<!-- 引入Web模块,需添加spring-boot-starter-web模块�? -->
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-web</artifactId>
26+
<exclusions>
27+
<exclusion>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-tomcat</artifactId>
30+
</exclusion>
31+
</exclusions>
32+
</dependency>
33+
<!-- END -->
34+
<!-- 排除Tomcat,使用jetty -->
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-jetty</artifactId>
38+
</dependency>
39+
<!-- devtools:是spring boot的一个热部署工具 -->
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-devtools</artifactId>
43+
<optional>true</optional>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-starter-test</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.slf4j</groupId>
52+
<artifactId>slf4j-api</artifactId>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.slf4j</groupId>
56+
<artifactId>jcl-over-slf4j</artifactId>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.slf4j</groupId>
60+
<artifactId>log4j-over-slf4j</artifactId>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.slf4j</groupId>
64+
<artifactId>jul-to-slf4j</artifactId>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.jboss.logging</groupId>
68+
<artifactId>jboss-logging</artifactId>
69+
</dependency>
70+
<dependency>
71+
<groupId>ch.qos.logback</groupId>
72+
<artifactId>logback-classic</artifactId>
73+
</dependency>
74+
<dependency>
75+
<groupId>ch.qos.logback</groupId>
76+
<artifactId>logback-core</artifactId>
77+
</dependency>
78+
<dependency>
79+
<groupId>com.alibaba</groupId>
80+
<artifactId>fastjson</artifactId>
81+
</dependency>
82+
</dependencies>
83+
84+
<build>
85+
<plugins>
86+
<plugin>
87+
<groupId>org.springframework.boot</groupId>
88+
<artifactId>spring-boot-maven-plugin</artifactId>
89+
<configuration>
90+
<fork>true</fork>
91+
</configuration>
92+
</plugin>
93+
<plugin>
94+
<groupId>org.apache.maven.plugins</groupId>
95+
<artifactId>maven-compiler-plugin</artifactId>
96+
<configuration>
97+
<source>1.8</source>
98+
<target>1.8</target>
99+
<meminitial>128m</meminitial>
100+
<maxmem>512m</maxmem>
101+
<fork>true</fork>
102+
<compilerVersion>1.3</compilerVersion>
103+
<encoding>UTF-8</encoding>
104+
<compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument>
105+
</configuration>
106+
</plugin>
107+
</plugins>
108+
</build>
13109
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>cn.timebusker</groupId>
7+
<artifactId>spring-boot-15-Redis</artifactId>
8+
<version>2.0.0</version>
9+
</parent>
10+
<artifactId>spring-boot-15-Redis-cache</artifactId>
11+
<name>spring-boot-15-Redis-cache</name>
12+
<url>http://maven.apache.org</url>
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
<dependencies>
17+
</dependencies>
18+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.timebusker;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class App {
8+
9+
public static void main(String[] args) {
10+
// spring boot实践
11+
SpringApplication.run(App.class, args);
12+
}
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cn.timebusker.web;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestMethod;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
@RestController
10+
public class indexController {
11+
12+
private final static Logger logger = LoggerFactory.getLogger(indexController.class);
13+
14+
@RequestMapping(value = { "/**", "/" }, method = RequestMethod.GET)
15+
public Long createLogs() {
16+
logger.info("----------------------------------INFO");
17+
return System.currentTimeMillis();
18+
}
19+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 项目contextPath,一般在正式发布版本中,我们不配置
2+
# server.context-path=/mq
3+
# 错误页,指定发生错误时,跳转的URL。请查看BasicErrorController源码便知
4+
server.error.path=/error
5+
# 服务端口
6+
server.port=80
7+
# session最大超时时间(分钟),默认为30
8+
server.session-timeout=60
9+
# 该服务绑定IP地址,启动服务器时如本机不是该IP地址则抛出异常启动失败,只有特殊需求的情况下才配置
10+
# server.address=192.168.16.11
11+
12+
# ACTIVEMQ
13+
# 配置消息模型为pub/sub方式:true是Topic;如果是false或者默认,则是queue
14+
spring.jms.pub-sub-domain=true
15+
# URL of the ActiveMQ broker. Auto-generated by default. For instance `tcp://localhost:61616`
16+
# spring.activemq.broker-url=
17+
# Specify if the default broker URL should be in memory. Ignored if an explicit broker has been specified.
18+
# spring.activemq.in-memory=true
19+
# Login password of the broker.
20+
# spring.activemq.password=
21+
# Login user of the broker.
22+
# spring.activemq.user=
23+
# Trust all packages.
24+
# spring.activemq.packages.trust-all=false
25+
# Comma-separated list of specific packages to trust (when not trusting all packages).
26+
# spring.activemq.packages.trusted=
27+
# See PooledConnectionFactory.
28+
# spring.activemq.pool.configuration.*=
29+
# Whether a PooledConnectionFactory should be created instead of a regular ConnectionFactory.
30+
# spring.activemq.pool.enabled=false
31+
# Connection expiration timeout in milliseconds.
32+
# spring.activemq.pool.expiry-timeout=0
33+
# Connection idle timeout in milliseconds.
34+
# spring.activemq.pool.idle-timeout=30000
35+
# Maximum number of pooled connections.
36+
# spring.activemq.pool.max-connections=1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#Spring Boot 会自动扫描classpath下的application.properties文件,如果有就加载文件配置
2+
3+
4+
########################################################################################
5+
#Spring Boot中多环境配置文件名需要满足application-{profile}.properties的格式
6+
#{profile}对应你的环境标识
7+
#application-dev.properties:开发环境
8+
#application-test.properties:测试环境
9+
#application-prod.properties:生产环境
10+
# 多环境配置文件激活属性---开发、测试、生产
11+
spring.profiles.active=dev
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
4+
<!-- 开发环境 -->
5+
<springProfile name="dev">
6+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
7+
<encoder>
8+
<pattern>%date [%thread] %-5level %logger{80} || %msg%n</pattern>
9+
</encoder>
10+
</appender>
11+
<root level="info">
12+
<appender-ref ref="CONSOLE" />
13+
</root>
14+
</springProfile>
15+
16+
</configuration>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>cn.timebusker</groupId>
7+
<artifactId>spring-boot-15-Redis</artifactId>
8+
<version>2.0.0</version>
9+
</parent>
10+
<artifactId>spring-boot-15-Redis-mq</artifactId>
11+
<name>spring-boot-15-Redis-mq</name>
12+
<url>http://maven.apache.org</url>
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
<dependencies>
17+
</dependencies>
18+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.timebusker;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class App {
8+
9+
public static void main(String[] args) {
10+
// spring boot实践
11+
SpringApplication.run(App.class, args);
12+
}
13+
}

0 commit comments

Comments
 (0)