diff --git a/java/springboot系列/数据库/springboot整合mybatis(xml和注解).md b/java/springboot系列/数据库/1.springboot整合mybatis(xml和注解).md
similarity index 100%
rename from java/springboot系列/数据库/springboot整合mybatis(xml和注解).md
rename to java/springboot系列/数据库/1.springboot整合mybatis(xml和注解).md
diff --git a/java/springboot系列/数据库/2.springboot整合redis缓存.md b/java/springboot系列/数据库/2.springboot整合redis缓存.md
new file mode 100644
index 0000000..149ee53
--- /dev/null
+++ b/java/springboot系列/数据库/2.springboot整合redis缓存.md
@@ -0,0 +1,243 @@
+---
+id: '2019-02-22-14-59'
+date: '2019/02/22 14:59:00'
+title: 'springboot整合redis'
+tag: ['java', 'spring-boot', 'redis', 'nosql', '缓存']
+categories:
+ - 'java'
+ - 'spring boot学习'
+---
+
+
+
+**本篇原创发布于:**[springboot整合redis](http://www.tapme.top/blog/detail/2019-02-22-14-59)
+
+**项目源码:**:[github](https://github.com/FleyX/demo-project/tree/master/1.SSO%E5%8D%95%E7%82%B9%E7%99%BB%E5%BD%95/sso)
+
+ redis 作为一个高性能的内存数据库,如果不会用就太落伍了,之前在 node.js 中用过 redis,本篇记录如何将 redis 集成到 spring boot 中。提供 redis 操作类,和注解使用 redis 两种方式。主要内容如下:
+
+- docker 安装 redis
+- springboot 集成 redis
+- 编写 redis 操作类
+- 通过注解使用 redis
+
+# 安装 redis
+
+ 通过 docker 安装,docker compose 编排文件如下:
+
+```yml
+# docker-compose.yml
+version: '2'
+services:
+ redis:
+ container_name: redis
+ image: redis:3.2.10
+ ports:
+ - '6379:6379'
+```
+
+ 然后在`docker-compose.yml`所在目录使用`docker-compose up -d`命令,启动 redis。
+
+
+
+# 集成 springboot
+
+ 说明:springboot 版本为 2.1.3
+
+## 添加 maven 依赖
+
+ 只需添加`spring-boot-starter-data-redis`依赖即可
+
+```xml
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
+```
+
+## 编写 springboot 配置文件
+
+ 配置文件如下:
+
+```yaml
+server:
+ port: 8081
+ servlet:
+ context-path: /sso
+spring:
+ application:
+ name: SSO
+ cache:
+ type: redis
+ redis:
+ database: 0
+ host: 192.168.226.5
+ port: 6379
+ # 有密码填密码,没有密码不填
+ password:
+ # 连接超时时间(ms)
+ timeout: 1000ms
+ # 高版本springboot中使用jedis或者lettuce
+ jedis:
+ pool:
+ # 连接池最大连接数(负值表示无限制)
+ max-active: 8
+ # 连接池最大阻塞等待时间(负值无限制)
+ max-wait: 5000ms
+ # 最大空闲链接数
+ max-idle: 8
+ # 最小空闲链接数
+ min-idle: 0
+```
+
+## 编写配置类
+
+ 配置类代码如下:
+
+```java
+@EnableCaching//开启缓存
+@Configuration
+public class RedisConfig extends CachingConfigurerSupport {
+
+ /**
+ * 设置缓存管理器,这里可以配置默认过期时间等
+ *
+ * @param connectionFactory 连接池
+ * @return
+ */
+ @Bean
+ public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
+ RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration
+ .defaultCacheConfig()
+ .entryTtl(Duration.ofSeconds(60));
+ //注意:请勿使用先new 配置对象,然后在调用entryTtl方法的方式来操作
+ //会导致配置不生效,原因是调用.entryTtl方法会返回一个新的配置对象,而不是在原来的配置对象上修改
+
+ RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
+ RedisCacheManager manager = new RedisCacheManager(redisCacheWriter, redisCacheConfiguration);
+ return manager;
+ }
+
+ @SuppressWarnings("all")
+ @Bean
+ public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
+ StringRedisTemplate template = new StringRedisTemplate(factory);
+ Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
+ ObjectMapper om = new ObjectMapper();
+ om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
+ om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
+ jackson2JsonRedisSerializer.setObjectMapper(om);
+ RedisSerializer stringSerializer = new StringRedisSerializer();
+ template.setKeySerializer(stringSerializer);
+ template.setValueSerializer(jackson2JsonRedisSerializer);
+ template.setHashKeySerializer(stringSerializer);
+ template.setHashValueSerializer(jackson2JsonRedisSerializer);
+ template.afterPropertiesSet();
+ return template;
+ }
+}
+```
+
+## 使用方法
+
+ 有两种方法来进行缓存操作,一种是在方法上添加缓存注解实现各种操作,一种是手动控制。个人比较喜欢手动控制,觉得这样都在自己的掌控中。
+
+### 通过注解使用
+
+ 主要有以下 5 个注解:
+
+- `@CacheConfig`: 类级别缓存,设置缓存 key 前缀之类的
+- `@Cacheable`: 触发缓存入口
+- `@CacheEvict`: 触发移除缓存
+- `@CachePut`: 更新缓存
+- `@Caching`: 组合缓存
+
+#### @CacheConfig
+
+ 该注解可以将缓存分类,它是类级别注解,主要用于给某个类的缓存全局配置,例子如下:
+
+```java
+@CacheConfig(cacheNames = "redis_test")
+@Service
+public class RedisService {
+ //....
+}
+```
+
+上面 CacheConfig 会给类下通过注解生成的 key 加上 redis_test 的前缀。
+
+#### @Cacheable
+
+ 方法级别注解,根据 key 查询缓存:
+
+- 如果 key 不存在,将方法返回值缓存到 redis 中
+- 如果 key 存在,直接从缓存中取值
+ 例子如下:
+
+```java
+ /**
+ * 缓存时间,首次查询后会缓存结果,key中的值可使用表达式计算.
+ * 如不提供key,将使用默认key构造方法生成一个key
+ * @return long
+ */
+ @Cacheable(key = "'currentTime'")
+ public long getTime() {
+ return System.currentTimeMillis();
+ }
+```
+
+多次调用此段代码会发现每次返回的值都是一样的。
+
+#### CachePut
+
+ 用于更新缓存,每次调用都会想 db 请求,缓存数据
+
+- 如果 key 存在,更新内容
+- 如果 key 不存在,插入内容
+
+代码如下:
+
+```java
+/**
+ * 一般用于更新查插入操作,每次都会请求db
+ */
+ @CachePut(key = "'currentTime'+#id")
+ public long updateTime(String id) {
+ return System.currentTimeMillis();
+ }
+```
+
+每次调用此方法都会根据 key 刷新 redis 中的缓存数据。
+
+#### @CacheEvict
+
+ 根据 key 删除缓存中的数据。allEntries=true 表示删除缓存中所有数据。
+代码如下:
+
+```java
+ @CacheEvict(key = "'currentTime'+#id",allEntries=false)
+ public void deleteTime(String id) {
+ }
+```
+
+#### @Caching
+
+ 本注解可将其他注解组合起来使用。比如下面的例子:
+
+```java
+ //value属性为key指定前缀
+ @Caching(put = {@CachePut(value = "user", key = "'name_'+#user.name"),
+ @CachePut(value = "user", key = "'pass_'+#user.password")})
+ public User testCaching(User user) {
+ return user;
+ }
+```
+上面的代码执行后将在redis中插入两条记录。使用`keys *`将看到如下结果:
+
+
+
+### 手动控制
+
+ 手动控制就相当于mybatis的手写sql语句,需要调用`redisTemplate`中的各种方法来进行缓存查询,缓存更新,缓存删除等操作。
+
+ 使用方法参见util/RedisUtil中的方法。`redisTemplate`基本可以实现所有的redis操作。
diff --git a/java/springboot系列/数据库/springboot整合redis.md b/java/springboot系列/数据库/springboot整合redis.md
deleted file mode 100644
index df2d22f..0000000
--- a/java/springboot系列/数据库/springboot整合redis.md
+++ /dev/null
@@ -1,36 +0,0 @@
----
-id: "2019-02-22-14-59"
-date: "2019/02/22 14:59:00"
-title: "springboot整合redis"
-tag: ["java","spring-boot","redis","nosql"]
-categories:
-- "java"
-- "spring boot学习"
----
-
- 项目源代码在 github,地址为:[https://github.com/FleyX/demo-project/tree/master/mybatis-test](https://github.com/FleyX/demo-project/tree/master/mybatis-test),有需要的自取。
-
- redis作为一个高性能的内存数据库,如果不会用就太落伍了,之前在node.js中用过redis,本篇记录如何将redis集成到spring boot中。提供redis操作类,和注解使用redis两种方式。主要内容如下:
-
-- docker安装redis
-- springboot 集成redis
-- 编写redis操作类
-- 通过注解使用redis
-
-# 安装redis
-
- 通过docker安装,docker compose编排文件如下:
-```yml
-# docker-compose.yml
-version: "3"
-services:
- redis:
- container_name: redis
- image: redis:3.2.10
- ports:
- - "6379:6379"
-```
-
- 然后在`docker-compose.yml`所在目录使用`docker-compose up -d`命令,启动redis。
-
-# 集成springboot
\ No newline at end of file
diff --git a/其他各种/docker部署hexo博客.md b/其他各种/docker部署hexo博客.md
index f45da62..50abc93 100644
--- a/其他各种/docker部署hexo博客.md
+++ b/其他各种/docker部署hexo博客.md
@@ -1,20 +1,20 @@
---
-id: "2019-03-03-15-42"
-date: "2019-03-03-15-42"
-title: "docker实现hexo博客自动部署,实时更新"
-tags: ["docker", "hexo", "next", "webhook"]
+id: '2019-03-03-15-42'
+date: '2019-03-03-15-42'
+title: 'docker实现hexo博客自动部署,实时更新'
+tags: ['docker', 'hexo', 'next', 'webhook']
categories:
- - "其他"
+ - '其他'
---
## 一、背景
- 你是否有过想要搭建一个hexo博客,但是看着那冗长的教程,唉声叹气?
+ 你是否有过想要搭建一个 hexo 博客,但是看着那冗长的教程,唉声叹气?
你是否因为每次发布新的博文,都要重新构建,部署而逐渐放弃写博客?
- 现在解决有了完美的解决办法了,一键构建,无需进行复杂的配置,开箱即用。同时支持github的webhook来实现实时构建,只需就行一次push操作,便能自动重新构建发布,无需手动操作。
+ 现在解决有了完美的解决办法了,一键构建,无需进行复杂的配置,开箱即用。同时支持 github 的 webhook 来实现实时构建,只需就行一次 push 操作,便能自动重新构建发布,无需手动操作。
- 详见[hexoBlog自动构建](https://github.com/FleyX/hexoBlog)
+ 详见[hexoBlog 自动构建](https://github.com/FleyX/hexoBlog)
使用方法:
@@ -30,16 +30,16 @@ git clone git@github.com:FleyX/hexoBlog.git

-**github配置webhock步骤如下:**
+**github 配置 webhock 步骤如下:**
以我的博文仓库(technology-note)为例:
-- 新增一个webhook
-
+- 新增一个 webhook
+ 
-- 配置webhook
-
+- 配置 webhook
+ 
- 将url的地址换为你的服务器地址,然后设置secret密钥,就OK了。再将密钥设置到docker-compose.yml中即可。
+ 将 url 的地址换为你的服务器地址,然后设置 secret 密钥,就 OK 了。再将密钥设置到 docker-compose.yml 中即可。
2. 博文 markdown 文件编写规范,详情参见[分布式事务.md](https://raw.githubusercontent.com/FleyX/technology-note/master/%E6%95%B0%E6%8D%AE%E5%BA%93/%E5%88%86%E5%B8%83%E5%BC%8F/%E5%88%86%E5%B8%83%E5%BC%8F%E4%BA%8B%E5%8A%A1.md):
@@ -47,13 +47,13 @@ git clone git@github.com:FleyX/hexoBlog.git
```yaml
---
-id: "2018-10-03-10-58"
-date: "2018/10/03 10:58"
-title: "分布式事务"
-tags: ["分布式", "sql", "2PC", "TCC", "异步补偿"]
+id: '2018-10-03-10-58'
+date: '2018/10/03 10:58'
+title: '分布式事务'
+tags: ['分布式', 'sql', '2PC', 'TCC', '异步补偿']
categories:
- - "数据库"
- - "分布式事务"
+ - '数据库'
+ - '分布式事务'
---
```
@@ -93,7 +93,7 @@ categories:
title: Hexo
subtitle: To strive, to seek, to find, and not to yield.
description: To strive, to seek, to find, and not to yield.
-keywords: ["java", "node", "html", "javascript"]
+keywords: ['java', 'node', 'html', 'javascript']
author: fleyX
```
@@ -101,26 +101,26 @@ author: fleyX
### 设置社交信息
- 编辑第178行social下项目:
+ 编辑第 178 行 social 下项目:

### 设置打赏
- 编辑327行reward下属性,设置支付宝/微信收款图片,可将图片放到`hexo/source/static/img`目录下。
+ 编辑 327 行 reward 下属性,设置支付宝/微信收款图片,可将图片放到`hexo/source/static/img`目录下。

-### 集成gitment评价
+### 集成 gitalk 评论
- 建议百度如何配置gitment,这里默认你已经会完毕,拥有id和secret。编辑570行,设置enable为true,然后加入你的信息:
+ 建议百度如何在 github 中配置 gitalk,这里默认你已经配置完毕,拥有 id 和 secret。编辑 570 行,设置 enable 为 true,然后加入你的信息:

-### 集成cnzz统计
+### 集成 cnzz 统计
- 设置635行,cnzz id即可
+ 设置 635 行,cnzz id 即可

-其他更加详细配置参看官方文档。
\ No newline at end of file
+其他更加详细配置参看官方文档。