Page Version Control with redis
npm install page-version-control> Page Version Control with redis 页面版本控制(通过redis)
``js
// 默认端口 6379
// 默认数据库 6
// $link: redis连接地址
// $name: redis实例名称
// $key: redis密码
// hz, us 为区域名称示例, 1个或多个都可以
{
"dbeta": {
"hz": {
"url": "$link",
"secret": "$name:$key",
"port": 6379,
"database": 6
},
"us": {
"url": "$link",
"secret": "$name:$key",
"port": 6379,
"database": 6
}
},
"release": {
"hz": {
"url": "$link",
"secret": "$name:$key",
"port": 6379,
"database": 6
},
"us": {
"url": "$link",
"secret": "$name:$key",
"port": 6379,
"database": 6
}
}
}
`
全局安装(可直接使用命令行)
``
$ npm install -g page-version-control`
直接使用命令行的话 就不需要书写调用代码, 直接在与node_modules平级的目录下放置下面这个配置文件即可:
pvc.config.js
var path = require('path')
module.exports = {
redisPath: path.resolve(__dirname, './redis.json'),
htmlPath: path.resolve(__dirname, './dist/index.html'),
prefix: 'your custom name'
}
``
局部安装`
$ npm install --save-dev page-version-control
js
// cjs
var pvc = require('page-version-control')
// es6
import pvc from 'page-version-control'
`
$3
`js
let env = 'dbeta'
let redisPath = path.resolve(__dirname, './redis.json')
let htmlPath = path.resolve(__dirname, './index.html')
var pvc = new Pvc({
htmlPath,
redisPath,
env,
prefix: 'icefire'
})
`
$3
!image
`js
// 只取当前版本之前的50条数据
pvc.showHistory()
`
$3
`js
pvc.getCurrentDetail().then(rs => {
console.log(rs)
})
`$3
!image
`js
// comment参数为必须
pvc.publish('comment.....')
`
$3
!image
`js
pvc.prev()
`
$3
!image
`js
// 48为版本索引
pvc.rollback(48)
`
基础API
#### 基础redis操作
1. exists
2. keys
3. get
4. set
5. hmget
6. hmset
7. hgetall#### 队列化后执行
1. exec
`js
// 例子
pvc.create()
pvc.set('key1', '001')
pvc.set('key2', '002')
pvc.set('key3', '003')
pvc.getAllKeys()
pvc.get('key1')
pvc.get('key2')
pvc.get('key3')
pvc.hmset('key4', {
name: 'yoyo',
gender: 2
})
pvc.hgetall('key4')
pvc.exec().then(rs => {
console.log(rs)
})
``