UNPKG

@hippy/debug-server-next

Version:
67 lines (66 loc) 2.25 kB
"use strict"; /* * Tencent is pleased to support the open source community by making * Hippy available. * * Copyright (C) 2017-2019 THL A29 Limited, a Tencent company. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.MemoryDB = void 0; const base_db_1 = require("../base-db"); /** * store data in memory, all value use redis hashmap type */ class MemoryDB extends base_db_1.BaseDB { async init() { } async get(field) { const hashmap = MemoryDB.hashmapStore.get(this.key); if (!hashmap) return; return hashmap.get(field); } async getAll() { const hashmap = MemoryDB.hashmapStore.get(this.key) || new Map(); return Array.from(hashmap.values()); } async upsert(field, value) { if (!MemoryDB.hashmapStore.has(this.key)) { MemoryDB.hashmapStore.set(this.key, new Map()); } const hashMap = MemoryDB.hashmapStore.get(this.key); hashMap.set(field, value); } async delete(field) { const hashMap = MemoryDB.hashmapStore.get(this.key); hashMap === null || hashMap === void 0 ? void 0 : hashMap.delete(field); } async rPush(value) { if (!MemoryDB.listStore.has(this.key)) MemoryDB.listStore.set(this.key, []); const list = MemoryDB.listStore.get(this.key); list.push(value); } async getList() { const list = MemoryDB.listStore.get(this.key) || []; return list; } async clearList() { MemoryDB.listStore.set(this.key, []); } } exports.MemoryDB = MemoryDB; MemoryDB.hashmapStore = new Map(); MemoryDB.listStore = new Map();