microsoftarchive / redis

Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes
http://redis.io
Other
20.78k stars 5.37k forks source link

redis sadd command can not take effect when execute in callback function #540

Closed zhangjh closed 7 years ago

zhangjh commented 7 years ago

My test code is :

const redis = require("redis");
const client = redis.createClient(
  PORT,SERVER
);
client.on("error", function (err) {
  console.log("Error " + err);
});

client.smembers("test",function(err,reply) {
  if(err){
    console.error(err);
    return;
  }
  console.log(reply);
  if (!reply.length) {
    redis.sadd("test", "1");
  }
});

client.quit()

It output "[]",but expectedly,it will output "1". Am i wrong?

zhangjh commented 7 years ago

my redis version : redis-cli 3.2.100

zhangjh commented 7 years ago

Fixed,maybe I disconnet the connetion too early