finish share api
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Artem Anufrij
2023-02-15 23:36:19 +01:00
parent dc358e21dc
commit 408b6c3dc5
8 changed files with 205 additions and 48 deletions

View File

@@ -5,7 +5,7 @@ const config = server.config;
const redisUrl = "redis://" + config.redis.host + ":" + config.redis.port
const client = createClient({
url: redisUrl
url: redisUrl
});
client.on('error', (err) => console.log('Redis Client Error', err));
@@ -16,21 +16,30 @@ client.flushAll();
const expire = 57600; // 24h
exports.set = function (key, value) {
if (value) {
client.set(key, JSON.stringify(value));
client.expire(key, expire);
}
if (value) {
client.set(key, JSON.stringify(value));
client.expire(key, expire);
}
}
exports.get = function (key, callback) {
process.stdout.write("services/redis get '" + key + "'\n");
client.get(key).then(value => {
callback(JSON.parse(value));
});
client.expire(key, expire);
process.stdout.write("services/redis get '" + key + "'\n");
client.get(key).then(value => {
callback(JSON.parse(value));
});
client.expire(key, expire);
}
exports.del = function (key, callback) {
process.stdout.write("services/redis del '" + key + "'\n");
client.del(key).then(() => {
if (callback) {
callback();
}
});
}
exports.flushAll = function () {
client.flushAll();
process.stdout.write("services/redis flushAll()\n");
client.flushAll();
process.stdout.write("services/redis flushAll()\n");
}