lv-server
v2.0.11
Published
Standalone LevelDB file server.Put data into it using multilevel and get it served over socket.
Downloads
12
Maintainers
Readme
lv-server
基于leveldb网络缓存服务,支持服务器集群,用户密码认证,对数据生命周期管理.
此package为服务端,客户端调用连接用lv-client
Install
npm i lv-server
Usage
import {LevelServer} from 'lv-server'
const levelServer = new LevelServer(options)
levelServer.createServer()
options
Options相关参数
'port'
-number
类型,监听商品'users'
-Array<object>
类型,认证用户'username'
-string
类型,用户名'password'
-string
类型,密码
'path'
-string
类型,数据和日志存放路径
const options= {
port: 7777,
users: [{username: 'user1', password: '123123'}],
path: '/opt/yourpath'
}
Event
levelServer.on(eventName[, msg])
'listening'
- 监听中,正常运行事件'error'
- 出错事件,出错可进行重启
levelServer.on('listening', (port) => {
console.log('服务已经启动,端口:', port);
})
levelServer.on('error', (err) => {
console.error(err);
if (err.code === 'EADDRINUSE') {
console.error(`端口:${config.port}被占用`);
}else{
setTimeout(() => {
console.log('重启服务');
levelServer.createServer();
}, 1000);
}
})
levelServer.on('query', (query,reslut,timespan) => {
if(!timespan){
console.log('START',query);
}else{
console.log('END',reslut,timespan);
}
})