增加inited函数

This commit is contained in:
kangkang520
2018-12-03 11:11:27 +08:00
parent fe2d14c186
commit 361ca3ad4a
2 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "cluster-memdb", "name": "cluster-memdb",
"version": "1.0.3", "version": "1.0.4",
"description": "key-value memory database for single process application and cluster application", "description": "key-value memory database for single process application and cluster application",
"main": "dist/index.js", "main": "dist/index.js",
"types": "typings/index.d.js", "types": "typings/index.d.js",

View File

@ -47,6 +47,8 @@ if (cluster.isMaster) {
else if (res.type == 'keys') result = await db.keys() else if (res.type == 'keys') result = await db.keys()
//数据查询 //数据查询
else if (res.type == 'find') result = await db.find(res.data) else if (res.type == 'find') result = await db.find(res.data)
//是否初始化
else if (res.type == 'inited') result = await db.inited()
//反馈消息给客户端 //反馈消息给客户端
worker.send(JSON.stringify({ id: res.id, messageType: MESSAGE_TYPE_NAME, data: result, type: res.type })) worker.send(JSON.stringify({ id: res.id, messageType: MESSAGE_TYPE_NAME, data: result, type: res.type }))
} }
@ -187,6 +189,14 @@ export function memdb(db: string, keyName: string) {
else return Object.keys(s.datas() || {}) else return Object.keys(s.datas() || {})
} }
/**
* 数据是否初始化
*/
async function inited(): Promise<boolean> {
if (sendable) return await send('inited', db, keyName, null)
else return s.datas() !== null
}
//返回结果 //返回结果
return { return {
save, save,
@ -197,6 +207,7 @@ export function memdb(db: string, keyName: string) {
getByKeys, getByKeys,
find, find,
keys, keys,
inited,
} }
} }