keyv-anyredis
Version:
Storage adapter for Keyv that works with multiple Redis clients, including cluster clients
49 lines • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isCompatibleNodeRedisV4Client = exports.isCompatiblePromiseRedisClient = void 0;
function isPromiseClient(client) {
const result = client.get('hello');
if (typeof result?.then === 'function') {
result.then(
// Handle fulfilled and rejected callbacks (prevent unhandled Promise rejection)
() => {
// Nothing
}, error => {
console.error(error);
});
return true;
}
return false;
}
function isCompatiblePromiseRedisClient(client) {
// It must have lowercase methods
for (const method of ['get', 'set', 'del', 'sadd', 'srem', 'smembers']) {
if (!(method in client)) {
return false;
}
}
return isPromiseClient(client);
}
exports.isCompatiblePromiseRedisClient = isCompatiblePromiseRedisClient;
function isCompatibleNodeRedisV4Client(client) {
// It must have uppercase methods
for (const method of [
'GET',
'get',
'SET',
'set',
'DEL',
'del',
'SADD',
'SREM',
'SMEMBERS',
'SISMEMBER'
]) {
if (!(method in client)) {
return false;
}
}
return isPromiseClient(client);
}
exports.isCompatibleNodeRedisV4Client = isCompatibleNodeRedisV4Client;
//# sourceMappingURL=compatible-redis-client.js.map