Reputation: 317
Is it possible to send arbitrary commands to Redis using ioredis for Node JS?
For example, I'm using the new RediSearch module, and want to create an index using the command:
FT.CREATE test SCHEMA title TEXT WEIGHT 5.0
How would I send this command using ioredis?
Upvotes: 5
Views: 6844
Reputation: 1703
Alternatively, these variants will work as well:
redis.call('M.CUSTOMCMD', ['arg1', 'arg2', 'arg3'],
function(err, value) { /* ... */ });
// if you need batch custom/module commands
redis.multi([
['call', 'M.CUSTOMCMD', 'arg1', 'arg2', 'arg3'],
['call', 'M.OTHERCMD', 'arg-a', 'arg-b', 'arg-c', 'arg-d']
])
.exec(function(err, value) { /* ... */ });
Upvotes: 4
Reputation: 1215
This will get you there, although not sure about the response encoding:
var
Redis = require('ioredis'),
redis = new Redis('redis://:[yourpassword]@127.0.0.1');
redis.sendCommand(
new Redis.Command(
'FT.CREATE',
['test','SCHEMA','title','TEXT','WEIGHT','5.0'],
'utf-8',
function(err,value) {
if (err) throw err;
console.log(value.toString()); //-> 'OK'
}
)
);
If you're willing to search to node_redis, there is a pre-built RediSearch plugin that supports all the RediSearch commands. (Disclosure: I wrote it)
Upvotes: 9