diff --git a/package.json b/package.json index be8abc6..d58a43e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cluster-memdb", - "version": "1.0.3", + "version": "1.0.4", "description": "key-value memory database for single process application and cluster application", "main": "dist/index.js", "types": "typings/index.d.js", diff --git a/src/db.ts b/src/db.ts index 2be1ac5..e81e002 100644 --- a/src/db.ts +++ b/src/db.ts @@ -47,6 +47,8 @@ if (cluster.isMaster) { else if (res.type == 'keys') result = await db.keys() //数据查询 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 })) } @@ -187,6 +189,14 @@ export function memdb(db: string, keyName: string) { else return Object.keys(s.datas() || {}) } + /** + * 数据是否初始化 + */ + async function inited(): Promise { + if (sendable) return await send('inited', db, keyName, null) + else return s.datas() !== null + } + //返回结果 return { save, @@ -197,6 +207,7 @@ export function memdb(db: string, keyName: string) { getByKeys, find, keys, + inited, } }