hapijs / catbox-redis

Redis adapter for catbox
Other
69 stars 63 forks source link

Support RedisJSON for storing JSON objects, change to Redis.call instead of Redis.get/set #122

Open johnmanko opened 2 years ago

johnmanko commented 2 years ago

Support plan

Context

What problem are you trying to solve?

This project uses ioredis's Redis.psetex/get for writing and reading user data as string data. This requires applications to deserialize cache data when reading.

Do you have a new or modified API suggestion to solve the problem?

Alternatively, class Redis has a call method that supports direct Redis commands, such as GET, SET, JSON.GET, JSON.SET, etc. This project should be changed to exclusively use the call method and support all Redis supported commands. This can easily be done using a modifier to prefix commands.

Examples:

   redis.call('set', 'foo', 'bar');
   redis.call('json.set', 'foo', {bar: 'pickles'});
   redis.expire('foo', seconds);

With prefix = '', 'json.', etc based on plugin option

   redis.call(`${prefix}set`, 'foo', {bar: 'pickles'});
   redis.expire('foo', seconds);

There does seems to some inconsistency between the set/psetex methods and call. It would be nice to pass command options right on the call, but I guess the extra expire can take care of that if it can be done in an async way.

kanongil commented 2 years ago

I don't see how the native JSON.<X> methods can give any advantage to us. They allow to directly access embedded JSON objects / values, but we always use the root. The interface to the REDIS server is still string-based, so there is no change in serialization, except that ioredis now controls it.

These new methods are also not compatible with the open-source releases of redis.

Finally, changing to use call will break the interface for users that use the client option with alternative or custom clients.