rc-plugin/utils/redis-util.js
2025-09-11 13:10:29 +08:00

36 lines
793 B
JavaScript
Raw Permalink 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>}
* @example
* const exists = await redisExistKey('myKey');
* console.log(exists); // true or false
*/
export async function redisExistKey(key) {
return redis.exists(key);
}
/**
* 获取某个key的值
* @param key
* @returns {Promise<Object>}
* @example
* const value = await redisGetKey('myKey');
* console.log(value); // { ... }
*/
export async function redisGetKey(key) {
return JSON.parse(await redis.get(key));
}
/**
* 为某个key设置值value必须是个键值对
* @param key
* @param value
* @returns {Promise<*>}
* @example
* await redisSetKey('myKey', { foo: 'bar' });
*/
export async function redisSetKey(key, value = {}) {
return redis.set(key, JSON.stringify(value));
}