Reputation: 32391
Is there any way to remove/delete an entry by key, using Node_redis? I can't see any such option from the docs..
Upvotes: 61
Views: 99378
Reputation: 1
Suppose we want to delete key="randomkey"
:
redisClient.del(key, function(err, reply) {
if (err)
throw err;
console.log("deleteRedisKey",reply)
resolve(reply);
});
Upvotes: 0
Reputation: 2522
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);
});
Upvotes: 9
Reputation: 1705
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
Upvotes: 23
Reputation: 1344
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.
Upvotes: 52