-
Notifications
You must be signed in to change notification settings - Fork 87
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Hi, it would be great to have some kind of adapter API for third party Redis clients such as ioredis
. This would eliminate the need to mix ioredis
and redis
usage in an existing codebase which uses ioredis
.
I’ve hacked together support for ioredis
(not thoroughly tested yet) by doing this:
ioredis-client-adapter.js
import { Redis } from 'ioredis';
export const createClient = (redis: Redis) => {
redis.hGetAll = redis.hgetall;
redis.hSet = redis.hset;
redis.executeIsolated = redis.exec;
redis.__client = 'ioredis'
return redis;
};
Patched redis-om
Client file
/* <PATCH-START> */
async jsonget(key) {
this.validateRedisOpen();
const json = this.redis.__client && this.redis.__client === 'ioredis'
? await this.redis.call('JSON.GET', [key, "."])
: await this.redis.sendCommand<string>(['JSON.GET', key, '.'])
return JSON.parse(json);
}
async jsonset(key, data) {
this.validateRedisOpen();
const json = JSON.stringify(data);
if (this.redis.__client && this.redis.__client === 'ioredis') {
await this.redis.call('JSON.SET', [key, ".", json]);
} else {
await this.redis.sendCommand<string>(['JSON.SET', key, '.', json]);
}
}
/* <PATCH-END> */
cenk1cenk2, vamshi9666, paulhbarker, anne-montoya, chiawendt and 2 more
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request