Is there any way to remove/delete an entry by key, using Node_redis? I can't see any such option from the docs..
Here you can see what redis commands are work in this library node_redis github
As you can see "del" command is in the list.
And this command allow you delete keys from selected db as Jonatan answered.
You can del
use like this:
redis.del('SampleKey');
node-redis
–
Ppm Here you can see what redis commands are work in this library node_redis github
As you can see "del" command is in the list.
And this command allow you delete keys from selected db as Jonatan answered.
As everyone above has stated you can use del function. You can assure the successful delete operation using this syntax.
client.del('dummyvalue', function(err, response) {
if (response == 1) {
console.log("Deleted Successfully!")
} else{
console.log("Cannot delete")
}
})
Because the DEL command will return (integer) 1
in successful operation.
redis 127.0.0.1:6379> DEL key
Success: (integer) 1
Unsuccess: (integer) 0
Hope this will help you
let redis = require("redis");
var redisclient = redis.createClient({
host: "localhost",
port: 6379
});
redisclient.on("connect", function () {
console.log("Redis Connected");
});
redisclient.on('ready', function () {
console.log("Redis Ready");
});
redisclient.set("framework", "AngularJS", function (err, reply) {
console.log("Redis Set" , reply);
});
redisclient.get("framework", function (err, reply) {
console.log("Redis Get", reply);
});
redisclient.del("framework",function (err, reply) {
console.log("Redis Del", reply);
});
Suppose we want to delete key="randomkey"
:
redisClient.del(key, function(err, reply) {
if (err)
throw err;
console.log("deleteRedisKey",reply)
resolve(reply);
});
Using sailsJs you can do this :
let id_todel = "5b845f9ea7f954bb732fdc52";
await sails.getDatastore('redis').leaseConnection(function during(db, proceed) {
db.del(id_todel );
return proceed(undefined, undefined);
});
sails
–
Tourane © 2022 - 2024 — McMap. All rights reserved.