Skip to content

Commit

Permalink
Idk, I did something weird in git and this dissapeared...
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele committed Jul 1, 2020
1 parent 116fe18 commit 91ce586
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions api/helpers/redis/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,45 @@ module.exports = {


fn: async function (inputs, exits) {
await sails.helpers.redis.ensureCacheExists();

sails.cache[inputs.keyString] = inputs.value;
return exits.success();
if (process.env.REDISSTRING) {

if (inputs.ex) {
if (_.isUndefined(inputs.ttl)) {
return exits.error(`When setting ex true you must provide a TTL.`)
}

sails.getDatastore('cache').leaseConnection(function during(redisConnection, proceed) {
redisConnection.set(inputs.keyString, inputs.value, 'EX', inputs.ttl, (err, reply) => {
if (err) return proceed(err);

return proceed(undefined, reply)
})
}).exec((err, result) => {
if (err) return exits.error(err);

return exits.success(result);
})

} else {

sails.getDatastore('cache').leaseConnection(function during(redisConnection, proceed) {
redisConnection.set(inputs.keyString, inputs.value, (err, reply) => {
if (err) return proceed(err);

return proceed(undefined, reply)
})
}).exec((err, result) => {
if (err) return exits.error(err);

return exits.success(result);
})
}
} else {
sails.cache[inputs.keyString] = inputs.value;
return exits.success();
}

}

};
};

0 comments on commit 91ce586

Please sign in to comment.