-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
3,130 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Maven-profile配置 | ||
|
||
用Maven的小伙伴都知道,Maven的宗旨是约定优于配置(Convention Over Configuration)。 | ||
|
||
在宗旨的前提下Maven也提供了个性化定制的Profile,让我们看看用法哈! | ||
|
||
首先让我们一起看看Maven中的属性,这个用的挺多的: | ||
|
||
注:以下属性请在pom文件中使用,项目中使用默认是不支持的需要自己配置。 | ||
|
||
内置属性: ${basedir}项目根目录 | ||
|
||
${version} 项目版本号 | ||
|
||
Pom属性: ${project.artifactId} | ||
|
||
${project.build.sourceDirectory} | ||
|
||
${project.build.testSourceDirectory} | ||
|
||
${project.build.directory} | ||
|
||
${project.outputDirectory} | ||
|
||
${project.testOutputDirectory} | ||
|
||
${project.groupId} | ||
|
||
${project.version} | ||
|
||
${project.build.finalName} | ||
|
||
自定义属性:Settings: ${settings.localRepository} ,引用settings.xml文件中的XML元素的值 | ||
|
||
Java系统属性: ${user.home} | ||
|
||
环境变量属性: ${env.JAVA_HOME} | ||
|
||
|
||
现在我们开始认识Profile,以下是一个简单的Profile结构体: | ||
|
||
```xml | ||
<profiles> | ||
<profile> | ||
<id>dev</id> | ||
<properties> | ||
<db.driver>com.mysql.jdbc.Driver</db.dirver> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
``` | ||
|
||
定义一个id为dev、属性db.driver为com.mysql.jdbc.Driver的Profile。 | ||
仅仅定义就行了吗?答案是否定的。我们需要激活Profile才能生效,我们可以通过```mvn clean install -P dev```激活! | ||
|
||
(注:```dev为激活ID,如果你想激活多个可以mvn clean install -P dev1,dev2使用,如果不想激活某一个用-P!dev1```) | ||
|
||
以上是一种激活方式,下面我们继续介绍其他激活方式 | ||
|
||
activeByDefault默认激活: | ||
|
||
```xml | ||
<profiles> | ||
<profile> | ||
<id>dev</id> | ||
<properties> | ||
<db.driver>com.mysql.jdbc.Driver</db.dirver> | ||
</properties> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
</profile> | ||
</profiles> | ||
``` | ||
|
||
settings.xml默认激活: | ||
|
||
```xml | ||
<settings> | ||
... | ||
<activeProfiles> | ||
<activeProfile>dev1</activeProfile> | ||
</activeProfiles> | ||
... | ||
</settings> | ||
``` | ||
|
||
|
||
系统属性激活: | ||
|
||
```xml | ||
<profiles> | ||
<profile> | ||
<id>dev</id> | ||
<properties> | ||
<db.driver>com.mysql.jdbc.Driver</db.dirver> | ||
</properties> | ||
<activation> | ||
<property> | ||
<name>test</name> | ||
<value>driver</value> | ||
</property> | ||
</activation> | ||
</profile> | ||
</profiles> | ||
``` | ||
|
||
注:上面表示test=driver时才激活, ```mvn clean install -Dtest=driver``` | ||
系统环境激活: | ||
|
||
```xml | ||
<profiles> | ||
<profile> | ||
<id>dev</id> | ||
<properties> | ||
<db.driver>com.mysql.jdbc.Driver</db.dirver> | ||
</properties> | ||
<activation> | ||
<jdk>[1.5,1.8)</jdk> | ||
<file> | ||
<missing>oracle.properties</missing> | ||
<exists>jdbc.properties</exists> | ||
</file> | ||
</activation> | ||
</profile> | ||
</profiles> | ||
``` | ||
注:上面表示jdk为1.5、1.6和1.7的时候激活,存在jdbc.properties文件情况,不存在oracle.properties文件情况激活 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
# Redis内存淘汰策略 | ||
|
||
|
||
## Redis淘汰策略 | ||
|
||
当达到最大内存```maxmemory```限制时,使用```maxmemory-policy```配置指令配置Redis的确切行为。 | ||
配置方式: maxmemory-policy options,默认为 | ||
|
||
- **noeviction**: 不会移除任何key,在写的时候直接返回error | ||
- **volatile-lru** : 使用LRU算法清除过期的key | ||
- **allkeys-lru** : 使用LRU算法清除key | ||
- **volatile-lfu** : 使用LFU算法清除过期的key | ||
- **allkeys-lfu** : 使用LFU算法清除key | ||
- **volatile-random** : 在过期的key中随机移除一个key | ||
- **allkeys-random** : 在所有key中随机移除一个key | ||
- **volatile-ttl** : 移除具有具有最近过期时间的key | ||
|
||
|
||
- [Redis-缓存](https://redis.io/topics/lru-cache) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Redis集群 | ||
|
||
## Redis集群方案有哪些 | ||
|
||
有两种: **codis架构**、**官方的redis cluster**。 | ||
|
||
## codis集群架构 | ||
|
||
codis是豌豆荚基于go编写的redis。 | ||
|
||
## 官方Redis Cluster集群方案 | ||
|
||
![](pictures/2.jpg) | ||
|
||
特点: | ||
|
||
- Redis官网推出的,先行扩展可以达到1000个节点 | ||
- 没有中心架构 | ||
- 一致性哈希思想 | ||
- 客户端直连redis | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Redis持久化 | ||
|
||
Redis支持两种数据持久化方式: **RDB**、**AOF**。 | ||
|
||
## RDB持久化 | ||
|
||
>根据配置的规则定时将内存中的数据持久化到硬盘上 | ||
将redis在内存中的数据记录定时dump到磁盘上的RDB持久化。 | ||
|
||
在指定的时间间格里将内存中的数据集快照写入磁盘,实际上是fork一个子进程,先将数据写入临时文件,写入成功后,再替换之前的文件,二进制压缩。 | ||
|
||
|
||
|
||
## AOF持久化 | ||
|
||
>每次执行写命令后将命令记录下来 | ||
AOF是将redis的操作日志以追加的方式写入文件。 | ||
|
||
和mysql类似,用日志的形式记录服务器的每一个写、删除操作;以文本的方式记录;通过查看该文件可以查看到详细的操作细节。 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Redis应用场景 | ||
|
||
- 计数器 | ||
- 排行榜 | ||
- session | ||
- 发布订阅 | ||
- 消息队列 | ||
|
||
## 实际场景 | ||
|
||
### 页面缓存 | ||
|
||
如果使用的是服务端内容渲染,可以使用redis将经常被请求的内容缓存起来,降低页面请求渲染的延迟 | ||
|
||
### 计数器/排行榜 | ||
|
||
Redis是一个运行在内存中的C程序。 | ||
Redis可以实现快速计数、查询缓存的功能,同时数据可以异步落地到其他数据源。 | ||
|
||
- 访问计数,用户每访问一次,计数就增加1 | ||
- 排行榜: 可以按时间、按数量、按集赞数进行排行 | ||
|
||
### session | ||
用户已经登陆的信息存放在redis中,每次用户更新或查询耕录信息可以直接从redis中获取。 | ||
|
||
### 消息队列 | ||
|
||
利用list数据类型可以构建一个简单高效的队列 | ||
|
||
### 发布订阅 | ||
|
||
pub/sub 是Redis内置的发布订阅功能,可以创建多人在线聊天系统、通知触发等 | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.