增加inited函数
This commit is contained in:
@ -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",
|
||||||
|
11
src/db.ts
11
src/db.ts
@ -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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user