Node_redis - how to remove a key?

72,330

Solution 1

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.

Solution 2

You can del use like this:

redis.del('SampleKey');

Solution 3

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

Solution 4

If I remember things correctly, del should do it.

Solution 5

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);
});
Share:
72,330

Related videos on Youtube

UpTheCreek
Author by

UpTheCreek

Updated on July 09, 2022

Comments

  • UpTheCreek
    UpTheCreek almost 2 years

    Is there any way to remove/delete an entry by key, using Node_redis? I can't see any such option from the docs..

  • TigOldBitties
    TigOldBitties over 7 years
    @Elephant hdel is not there but it works. The reference should be redis.io/commands since "It supports all Redis commands" (quoted from github github.com/NodeRedis/node_redis).
  • TigOldBitties
    TigOldBitties over 7 years
    @Elephant nevermind, i was looking at ioredis github.com/luin/ioredis/blob/master/lib/command.js
  • Sandwich
    Sandwich over 6 years
    This is the actual answer, giving a link to the redis docs was not an answer, the question was tagged with node-redis
  • Kaushik Thirthappa
    Kaushik Thirthappa about 5 years
    This is specific to sails
  • Jacob Degeling
    Jacob Degeling over 2 years
    The link provided is now 404ing on github.com.