Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

Redis performance with a Digital Ocean managed instance

I'm using nodeJS to connect my a Digital Ocean droplet (Ubuntu 20.04) to a Digital Ocean managed Redis instance. I'm using the ioredis npm library.

Consider the simple trivial code below. This code works perfectly with the public network name albeit taking around 400ms. If I use the private network name the entire script hangs. I've also tried the private IP 10...* but that doesn't work either.

Does anyone have any experience here or insight as to how to connect directly with the VPC? Is there a specific way to use the private network name?

const Redis = require("ioredis");

(async () => {
  // Spin up a redis client
  const redis = new Redis({
    host: "db-redis-**************-0.b.db.ondigitalocean.com",
    port: *****,
    username: "******",
    password: "**********",
    tls: {
      key: "",
      cert: "",
    },
  });

  console.time("Total time to write/read a 10 character string to redis");

  // Generate a random string
  const generateRandomString = (length = 6) =>
    Math.random().toString(20).substr(2, length);

  // Save data to the redis server with a TTL of 2 miniutes
  redis.set("redisTest", generateRandomString(10), "EX", 120);

  // Now read it back
  await redis.get("redisTest", function (err, result) {
    if (err) {
      console.error(err);
    } else {
      console.log("Data retrieved: ", result);
    }
  });

  // Done
  console.log("Done.");
  console.timeEnd("Total time to write/read a 10 character string to redis");
})();
question from:https://stackoverflow.com/questions/65660916/redis-performance-with-a-digital-ocean-managed-instance

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If using the private network address hangs during opening the connection, it's likely because your Droplet is not in the same VPC as your Redis database. In your case, it turned out that the Droplet and Redis were in different regions, so moving them to the same region (and ensuring they're in the same VPC within that region) should resolve the issue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...