使用ioredis发送任意命令到redis

有没有可能发送任意命令到Redis使用ioredis的节点JS?

例如,我正在使用新的RediSearch模块,并希望使用以下命令创build一个索引:

FT.CREATE test SCHEMA title TEXT WEIGHT 5.0 

我将如何使用ioredis发送此命令?

这会让你在那里,虽然不知道响应编码:

 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' } ) ); 

如果您愿意searchnode_redis ,则会有一个预先构build的RediSearch插件 ,它支持所有的RediSearch命令。 (披露:我写了)

或者,这些变体也可以工作:

 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) { /* ... */ });