Skip to content

Commit

Permalink
remove special handling for old node versions and fix some doc typos
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Seide <account-github@seide.st>
  • Loading branch information
sseide committed Dec 20, 2023
1 parent c54e4d5 commit 532239a
Showing 1 changed file with 12 additions and 31 deletions.
43 changes: 12 additions & 31 deletions lib/routes/apiv1.js
Expand Up @@ -322,7 +322,7 @@ function clusterNodes (redisConnection, callback) {
}

// this needs special handling for read-only mode. Must check all commands and classify
// if command to view or manipulatie data...
// if command to view or manipulate data...
function postExec (req, res) {
let cmd = req.body.cmd;
let connection = res.locals.connection;
Expand All @@ -337,7 +337,7 @@ function postExec (req, res) {
}
}

// block MULTI command as long as no support implemented. breaks to much things currently
// block MULTI command as long as no support implemented. breaks too many things currently
// same for MONITOR (#424)
if (commandName === 'multi' || commandName === 'monitor') {
return res.json({data: `ERROR: Command ${commandName} not supported via web cli`});
Expand All @@ -364,7 +364,7 @@ function postExec (req, res) {
*
* @param {string} command command name in lower case to check
* @param {Redis} connection active redis connection object with optional additional command list attached
* @return {boolean} true if coammd does not modify state of server
* @return {boolean} true if command does not modify state of server
*/
function isReadOnlyCommand(command, connection) {
// check dynamic command list for this connection if available
Expand All @@ -381,7 +381,7 @@ function isReadOnlyCommand(command, connection) {
}
}

/** this method returns a list with a list of active redis commands that can be send
/** this method returns a list with a list of active redis commands that can be sent
* via POST /exec route. It is used to initialise client-side CmdParser.
* There is no client side check to filter commands send via exec throu this list.
*
Expand Down Expand Up @@ -554,7 +554,7 @@ function getSizeLimitedHashFields(redisConnection, key, res, cb) {
return done(errDetails);
}
// if the strlen > 0 and the result value is undefined then we want to return an explicit
// null value so it can be interpretted as a deferred lookup value
// null value, so it can be interpreted as a deferred lookup value
fieldsAndValues[fieldNames[idx]] = (result[0] < config.get("ui.maxHashFieldSize"))? result[1] : null;
iterate(fieldNames, idx + 1, fieldsAndValues, done);
});
Expand Down Expand Up @@ -1006,7 +1006,7 @@ function editListValue (key, index, value, res, next) {
let redisConnection = res.locals.connection;
myutil.decodeHTMLEntities(value, function (decodedString) {
value = decodedString;
// for deletion - first set this specific index to TOMBSTONE and than delete all TOMBSTONES
// for deletion - first set this specific index to TOMBSTONE and then delete all TOMBSTONES
// otherwise all list entries with this old value will be deleted...
redisConnection.lset(key, index, value, function (err) {
if (err) {
Expand Down Expand Up @@ -1208,41 +1208,22 @@ function saveKey (req, res, next) {
}

function decodeKey (req, res, next) {
let key = req.params.key;
let redisConnection = res.locals.connection;
const key = req.params.key;
const redisConnection = res.locals.connection;

redisConnection.get(key, function (err, val) {
if (err) {
console.error('decodeKey', err);
return next(err);
}

let decoded = "";

if (typeof Buffer.toString === "function") {
// Node 5.10+
decoded = Buffer(val, "base64").toString("ascii");
} else {
// older Node versions
decoded = new Buffer(val, "base64").toString("ascii");
}

const decoded = Buffer(val, "base64").toString("ascii");
return res.send(decoded)
});
}

function encodeString (req, res, next) {
let val = req.params.stringValue;
let encoded = "";

if (typeof Buffer.from === "function") {
// Node 5.10+
encoded = Buffer(val).toString('base64');
} else {
// older Node versions
encoded = new Buffer(val).toString('base64');
}

const val = req.params.stringValue;
const encoded = Buffer(val).toString('base64');
return res.send(encoded)
}

Expand Down Expand Up @@ -1373,7 +1354,7 @@ function getKeysTree (req, res, next) {
// especially for cluster special handling needed
// might have 3 nodes, must iterate result of every node as there might be some follow-up
// calls to the server (TTL, number of hash keys and similar) for "leaf-keys" within this virtual tree level
// afterwards these lists can be unified to one -> there might be keys from different nodes from different server
// afterward these lists can be unified to one -> there might be keys from different nodes from different server
// for the same level:
// e.g. node 1: /blah: one sub-key group "blub/" and one string "yammy"
// node 2: /blah: two sub-key groups "blub/" "blubber/" and one string "yo"
Expand Down

0 comments on commit 532239a

Please sign in to comment.