Is there any way to remove/delete an entry by key, using Node_redis? I can't see any such option from the docs..
Asked
Active
Viewed 8.8k times
7 Answers
135
You can del
use like this:
redis.del('SampleKey');

jazgot
- 1,943
- 14
- 25

himanshu yadav
- 1,818
- 2
- 13
- 5
-
8This is the actual answer, giving a link to the redis docs was not an answer, the question was tagged with `node-redis` – Sandwich Oct 26 '17 at 11:18
53
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.

Jackson Egan
- 2,715
- 4
- 18
- 26

Elephant
- 1,346
- 10
- 11
-
@Elephant hdel is not there but it works. The reference should be https://redis.io/commands since "It supports all Redis commands" (quoted from github https://github.com/NodeRedis/node_redis). – TigOldBitties Jan 26 '17 at 08:50
-
@Elephant nevermind, i was looking at ioredis https://github.com/luin/ioredis/blob/master/lib/command.js – TigOldBitties Jan 30 '17 at 08:17
-
1
23
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

Tolsee
- 1,695
- 14
- 23
9
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);
});

Renish Gotecha
- 2,232
- 22
- 21
0
Suppose we want to delete key="randomkey"
:
redisClient.del(key, function(err, reply) {
if (err)
throw err;
console.log("deleteRedisKey",reply)
resolve(reply);
});

Tyler2P
- 2,324
- 26
- 22
- 31

Vishvas Jaiswal
- 1
- 2
-10
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);
});

Zakaria.dem
- 293
- 5
- 10