JiaHe's Blog

读万卷书,行万里路

原文地址 https://www.cnblogs.com/idea360/p/12391416.html

概述

接上一篇 Docker 实战之 MySQL 主从复制, 这里是 Docker 实战系列的第二篇,主要进行 Redis-Cluster 集群环境的快速搭建。Redis 作为基于键值对的 NoSQL 数据库,具有高性能、丰富的数据结构、持久化、高可用、分布式等特性,同时 Redis 本身非常稳定,已经得到业界的广泛认可和使用。

在 Redis 中,集群的解决方案有三种

  1. 主从复制
  2. 哨兵机制
  3. Cluster

Redis Cluster 是 Redis 的分布式解决方案,在 3.0 版本正式推出。

阅读全文 »

使用 fetch

fetch('//xxx.xxx.com/10.pdf', {
mode: 'cors'
}).then(res => res.blob()).then(blob => {
const blobURL = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.style.display = 'none'
link.href = blobURL
link.setAttribute('download', decodeURI('10.pdf'))
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(blobURL)
})

使用封装好的 $http

$http({
// 防止出现协议问题,这里不要写具体的 http 或者 https
url: '//xxx.xxx.com/10.pdf',
headerType: 'download',
method: 'get',
// 不指定默认从 content-disposition 头读取,后端接口也必须要设置 content-disposition 才能读取到
fileName: 'download.docx'
}).then(res => {

})

window.open

缺点:需要同域、可能会被拦截、浏览器支持预览的文件不会直接下载

window.open('//xxx.xxx.com/10.pdf')

form 表单提交

缺点:浏览器支持预览的文件不会直接下载

export function download (url, params = {}) {
const form = document.createElement('form')
form.method = 'post'
form.action = url
form.target = '_blank'
document.body.appendChild(form)
for (const key in params) {
const value = params[key]
if (value) {
const input = document.createElement('input')
input.setAttribute('type', 'hidden')
input.setAttribute('name', key)
if (isArray(value)) {
input.setAttribute('value', stringify(value))
} else {
input.setAttribute('value', value)
}
form.appendChild(input)
}
}
form.submit()
document.body.removeChild(form)
}

a 标签触发

缺点:可能会被拦截、浏览器支持预览的文件不会直接下载

const link = document.createElement('a')
link.style.display = 'none'
link.href = '//xxx.xxx.com/10.pdf'
link.setAttribute('download', decodeURI('10.pdf'))
document.body.appendChild(link)
link.click()
document.body.removeChild(link)

1 和 2 的方式,无论什么文件都是执行下载

两者都是基于同一个代码包数据库去拉取数据的。

最开始,yarn 是为了弥补 npm 的一些缺陷而出现的,到目前为止,两者的区别越来越小,主要是时间和使用体验上的一些不同了。

1、速度快

npm 第一次安装的对比 54.885s

yarn 第一次安装的对比 64.87s

npm 再次安装时间对比 34.961s

yarn 再次安装时间对比 19.824s

npm 删除包花费的时间对比 43.843s

yarn 删除包花费的时间对比 21.99s

2、npm 安装在国内基本都要设置镜像,而有些 npm 包需要额外的配置才能拉取下来

3、命令使用上,定义在 scripts 里面的命令,npm 需要加上 run,yarn 不需要

阅读全文 »

多个目录迁移到同一个新的仓库

1、克隆需要迁移的项目代码

git clone git@gitlab.alibaba-inc.com:maru/maru.git

2、同步所有分支信息

git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done

3、筛选出需要保留的目录

git filter-branch --index-filter 'git rm --cached -qr --ignore-unmatch -- . && git reset -q $GIT_COMMIT -- src public' --prune-empty -- --all

4、清理 .gitobject

git reset --hard
git for-each-ref --format="%(refname)" refs/original/ |xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --aggressive --prune=now

5、设置 origin

git remote rm origin
git remote add origin xxx.git

6、推送

git push --all

单个目录迁移到新仓库

只需要将上面的第三步改为下面的这条命令即可:

git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter src -- --all

查找替换

:[range]s/{pattern}/{string}/[flags]

:1,10s/from/to/ 表示在第1到第10行(包含第1,第10行)之间搜索替换
:10s/from/to/ 表示只在第10行搜索替换
:%s/from/to/ 表示在所有行中搜索替换
1,$s/from/to/ 同上

flags 有如下四个选项

  • c confirm,每次替换前询问;
  • e error, 不显示错误;
  • g globle,不询问,整行替换。如果不加 g 选项,则只替换每行的第一个匹配到的字符串;
  • i ignore,忽略大小写
  • 这些选项可以合并使用,如 cgi 表示不区分大小写,整行替换,替换前询问
阅读全文 »