Nginx在Docker下的安装
Nginx安装
Nginx挂载数据卷,配置文件夹和页面文件夹不会自动复制到宿主机,日志文件夹会自动复制。
需要先把配置文件手动复制到挂载数据卷里面,否则无法正常启动。页面文件可以根据需要决定是否手动复制。
mkdir -p /opt/volume/nginx
docker run --name nginx --rm -d nginx
docker cp nginx:/etc/nginx /opt/volume/nginx
mv /opt/volume/nginx/nginx /opt/volume/nginx/conf
# 复制页面文件夹内容,可选
docker cp nginx:/usr/share/nginx/html /opt/volume/nginx
docker ...
JavaScript实现面向对象
构造方法加原型对象实现
构造方法负责初始化变量
原型对象负责定义对象共享的方法和有默认值的属性
function Animal(name) {
this.name = name
}
Animal.prototype = {
name: '',
printName: function() {
console.log(this.name)
}
}
继承
通过原型对象来实现
function Dog(name) {
this.name = name
}
Dog.prototype = new Animal('')
Dog.prototype.bark = function() {
console.log('ba...
Spring通过Resource获取文件流
代码实例
文件路径可基于classpath,也可以使用文件系统的绝对路径
Resource resource = applicationContext.getResource("classpath:/redisson.yml");
InputStream inputStream = resource.getInputStream();
Vue Router测试
测试代码
mock一个VueRouter对象,断言被调用push方法
import {createLocalVue, mount} from '@vue/test-utils'
import LoginPage from '@/pages/LoginPage.vue'
import axios from '@/utils/axios'
import VueRouter from 'vue-router'
jest.mock('axios')
jest.mock('vue-router')
let testObject = {
container: {
},
prepare: {
async render() {...
Elasticsearch常用搜索
查询
全量查询
使用match_all
{
"query": {
"match_all": {}
}
}
单字段匹配查询
使用match,同时支持精确搜索与全文搜索,全文搜索时,搜索词分词,对应字段的内容存在一个词条匹配即可
{
"query": {
"match": {
"genre": "科幻"
}
}
}
多字段匹配查询
使用multi_match,至少一个字段存在一个词条匹配即可
{
"query": {
"multi_match": {
"query": "美国",
"fields...
使用InputStream读入字符串最佳实践
字节流,效率最高
byte[] buffer = new byte[1024];
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int length;
while ((length = inputStream.read(buffer)) != -1) {
byteArrayOutputStream.write(buffer, 0, length);
}
return byteArrayOutputStream.toString(StandardCharsets.UTF_8.name());
字符流,效率稍次
char[] buffer = new char[1024]...
缓存模式与实现
缓存特点
读取速度快,减少重复计算时间,以空间换时间
越是读多写少,越适合使用缓存
缓存模式
Cache Aside Pattern
使用最普遍的缓存模式,应用同时操作缓存和数据库。存在低概率的数据不一致
Spring声明式缓存整合Redis#cache aside pattern实现
定义
应用服务器读取数据先查看是否有缓存,有缓存直接取缓存,无缓存查询数据库,并将数据写入缓存
应用服务器更新数据,先更新数据库的数据,再删除相应的缓存数据
删除缓存失败
删除缓存失败将导致数据不一致
解决方案:缓存延时双删、异常重试再删缓存
数据不一致的情况
要获取的数据没有对应缓存
线程1
线程2
...
使用Canal同步MySQL到Elasticsearch
MySQL配置
开启MySQL的binlog写入,并指定binlog为ROW模式
my.cnf
[mysqld]
log-bin=mysql-bin
binlog-format=ROW
server_id=1
添加Canal使用的用户
CREATE USER canal IDENTIFIED BY 'canal';
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
FLUSH PRIVILEGES;
Canal配置
安装Canal
先把默认配置信息复制出来
mkdir -p /opt/volume/canal
docker run --name canal --...
axios模块化使用
axios全局配置
/src/utils/axios/index.js
import axios from 'axios'
import router from "@/router"
import {Message} from "element-ui"
// 全局响应处理拦截
axios.interceptors.response.use(response => {
return response
}, error => {
if (error.response && error.response.status === 401) {
router.push('/login').then(() => Me...
Vue引入axios
安装axios
npm install axios -S
安装vue-axios
npm install vue-axios -S
引入axios对象并配置
新增文件/src/utils/axios/index.js
import axios from 'axios'
import router from "@/router"
import {Message} from "element-ui"
axios.interceptors.response.use(response => {
return response
}, error => {
if (error.response && error.re...
332 post articles, 34 pages.