Are there any examples for using the REJSON module with the ioredis client?
Never used REJSON module before. However, redis.call should work well with all redis modules. For example:
var redis = new Redis()
redis.call('JSON.GET', 'foo')
Hey @luin , I know it's old topic, was wondering if this is possible with pipeline? sending a custom command
Thanks!
Edit: found the solution using createBuiltinCommand
redis.call('JSON.GET', 'foo')
redis.call()
How would one know that this method exists without it being documented in the API docs?
Hello @KromDaniel ,
would you mind to give an example ? I did not find how to use createBuiltinCommand with REJSON . Maybe that's because of the . in the commands.
Thanks.
@fas3r something like
// cache me, client is ioredis instance
const cmd = client.createBuiltinCommand('JSON.GET');
const getJson = cmd.string;
const getJsonBuffer = cmd.buffer;
// create pipeline
const pipeline = client.pipeline();
getJson.call(pipeline, 'argA', 'argB', 'argC');
getJsonBuffer.call(pipeline, 'argA', 'argB', 'argC');
pipeline.get('someThing');
// regular use
getJson.call(client, 'regular', 'get', 'json');
Another option to create commander is via:
const Commander = require('ioredis/lib/commander');
const commander = new Commander();
export const JSONGet = commander.createBulletinCommand("JSON.GET");
export const JSONSet = commander.createBulletinCommand("JSON.SET");
export const JSONDel = commander.createBulletinCommand("JSON.DEL");
Hello @KromDaniel ,
I did not know about commander I will look into this. If not I found this : https://github.com/evanhuang8/iorejson/blob/master/lib/rejson.js
Should be easy to adapt.
Thanks.
As per @luin 's comment, this worked well.
redis.call('JSON.GET', 'foo')
I just wanted to note that, the result from this is a Buffer object. So in order to parse it I had to do this.
redis.call('JSON.GET', 'foo')
.then(result => {
const stringified = result.toString('utf8');
const parsed = JSON.parse(stringified);
});
await redis.multi([
['call', 'CMS.INITBYPROB', `login_attempts:${currentTimeKey}`, '0.005', '0.005'],
['EXPIRE', `login_attempts:${currentTimeKey}`, '86400']
]).exec()
import * as Redis from 'ioredis'
export const client = new Redis(`redis://${process.env.REDIS_HOST}`)
client.createBuiltinCommand('CMS.INITBYPROB')
client.createBuiltinCommand('CMS.INCRBY')
client.createBuiltinCommand('CMS.QUERY')
await redis.multi([
['CMS.INITBYPROB', `login_attempts:${currentTimeKey}`, '0.005', '0.005'],
['EXPIRE', `login_attempts:${currentTimeKey}`, '86400']
]).exec()
neither are working for me.
Most helpful comment
Never used REJSON module before. However,
redis.callshould work well with all redis modules. For example: