node-redisai-js
v0.1.1
Published
RedisAI bindings for node_redis
Downloads
10
Maintainers
Readme
RedisAI bindings for node_redis node-redis
This package allows node-redis (2.8+) to interface with the RedisAI module.
To use this module, you will need Redis 4.0 or higher and the RedisAI module installed.
Usage
The RedisAI commands will be mapped to javascript-friendly names (ai.tensorset
becomes client.ai_tensorset
).
var
redis = require('redis'),
redisai = require('node-redisai-js');
redisai(redis);
Example
Running Models
Once a RedisAI Model key has been set with AI.MODELSET
it can be run with any Tensor keys from the database as its input. The model's output, after it was executed, is stored in RedisAI Tensors as well.
Here is a quick example!
The inputs for the example are the tensors stored under the 'tA' and 'tB' keys. Once the model's run had finished, a new RedisAI Tensor key called 'tC' is created and stores the model's output.
var redis = require('redis');
var redisai = require('node-redisai-js');
var fs = require('fs')
redisai(redis);
var client = redis.createClient();
var model_blob = fs.readFileSync('./examples/graph.pb');
client.ai_modelset(["mymodel", "TF", "CPU", "INPUTS", "a", "b", "OUTPUTS", "c", "BLOB", model_blob]);
client.ai_tensorset(["tA", "FLOAT", 2, "VALUES", 2, 3]);
client.ai_tensorset(["tB", "FLOAT", 2, "VALUES", 3, 5]);
client.ai_modelrun(["mymodel", "INPUTS", 'tA', 'tB', "OUTPUTS", 'tC']);
client.ai_tensorget(["tC", "VALUES"], function (err, res) {
console.log(res)
});
// Output should be
// [ '6', '15' ]
client.quit();