async getCodeByCache(namespace, id, { preCache }) { const key = redisKey(namespace, id); const versionID = await this.client.hget(key, 'versionID'); const cacheItem = this.cache[key]; if (cacheItem && cacheItem.versionID === versionID) { return cacheItem; } return getCodeAndPopulateCache(this, namespace, id, preCache); }
// Return the specified user karma. async function getUserKarma(user_id){ if ($user && (user_id == $user.id)) return $user.karma; let userkey = `user:${user_id}`; let karma = await $r.hget(userkey, 'karma'); return karma ? karma : 0; }
async putCode(namespace, id, code) { const key = redisKey(namespace, id); const data = { versionID: uuidV4(), updated: new Date().toISOString() }; const functionCode = await this.client.hget(key, 'code'); if (functionCode == null) { data.created = data.updated; } if (code.code) { data.code = code.code; data.hash = code.hash; } if (code.env) { data.env = JSON.stringify(code.env); } this.setNamespaceMember(namespace, id); return this.client.hmset(key, data); }
get(key) { return this.redisClient.hget(redisKey, key).then((val) => val === null ? undefined : JSON.parse(val)) }