rc-plugin/utils/redis-util.js
zhiyu1998 ceb242dfa8 feat: 1.8.0-beta 更新
更新内容如下:
1. 添加小飞机解析
2. 添加信任用户
2024-08-13 16:20:09 +08:00

42 lines
846 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 判断某个key是否存在
* @param key
* @returns {Promise<boolean>}
*/
export async function redisExistKey(key) {
return redis.exists(key);
}
/**
* 获取某个key的值
* @param key
* @returns {Promise<Object>}
*/
export async function redisGetKey(key) {
return JSON.parse(await redis.get(key));
}
/**
* 为某个key设置值value必须是个键值对
* @param key
* @param value
* @returns {Promise<*>}
*/
export async function redisSetKey(key, value = {}) {
return redis.set(
key,
JSON.stringify(value),
);
}
/**
* 判断是否存在这个key然后再取值如果没有就返回null
* @param key
* @returns {Promise<Object|Array>}
*/
export async function redisExistAndGetKey(key) {
if (await redisExistKey(key)) {
return redisGetKey(key);
}
return null;
}