Hi All,
We are working on a proxy requirement wherein we are trying to integrate REDIS database with DataPower to ingest user data. I have already explored the Webdis extension that exposes a HTTP interface to connect with REDIS DB but, that is introducing significant latency which isn't ideal for the application performance. Hence, we are trying to connect directly with REDIS instance to see if we are able to achieve it with low latency. Apparently, code snippets that I found after consistent google'ing is below
// Assuming the current message body contains the XML datavar input = session.input;
// Use apim.readInputAsXML or similar to get a NodeList// If the content type is already set to XML, you can directly use context.readAsXMLinput.readAsXML(function (error, nodelist) {
if (error) {
session.output.write("Error reading XML input: " + error);
return;
}
// Convert the NodeList/DOM object to a stringvar xmlString = XML.stringify(nodelist);
// Log for debugging (optional) session.output.write("Stringified XML: " + xmlString);
// Now, proceed to send this xmlString to Redis sendToRedis(xmlString);
});
function sendToRedis(xmlData) {
var redisHost = '10.10.10.1';
var redisPort = 6379;
var timeout = 10;
var redisKey = 'my:xml:key';
// Calculate lengths needed for RESP formatvar keyLen = redisKey.length;
var dataLen = xmlData.length;
// Construct the Redis SET command in RESP format: *3\r\n$3\r\nSET\r\n$<keyLen>\r\n<key>\r\n$<dataLen>\r\n<xmlData>\r\nvar redisCommand = "*3\r\n$3\r\nSET\r\n$" + keyLen + "\r\n" + redisKey + "\r\n$" + dataLen + "\r\n" + xmlData + "\r\n";
session.connect('tcp', redisHost + ':' + redisPort, timeout, function (err, connection) {
if (err) {
session.output.write("Connection error: " + err);
return;
}
connection.write(redisCommand);
connection.read(function (err, response) {
if (err) {
session.output.write("Read error: " + err);
} else {
session.output.write("Redis response: " + response.toString());
}
connection.end();
});
});
}
While, this code is not working , I would like to see if anyone else has connected to the Redis DB successfully if so, can you please share the code snippet or example.
Thanks,
Bharath
------------------------------
Bharath Marur
------------------------------