Skip to content

Instantly share code, notes, and snippets.

@ensean
Created April 10, 2024 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ensean/8b4f892270a75dc4a0200b7516a92410 to your computer and use it in GitHub Desktop.
Save ensean/8b4f892270a75dc4a0200b7516a92410 to your computer and use it in GitHub Desktop.
node connect to memorydb for redis
import { Cluster } from "ioredis";
const host = "clustercfg.test.xxxxxx.memorydb.ap-northeast-1.amazonaws.com";
const port = 6379;
export const redis = new Cluster([{ host, port }], {
dnsLookup: (address, callback) => callback(null, address),
redisOptions: {
tls: {},
},
});
await redis.set("abc", 1234)
var val = await redis.get("abc")
console.log(val)
@ensean
Copy link
Author

ensean commented Apr 10, 2024

  • TLS 未开启时连接代码
import { Cluster } from "ioredis";

const host = "test-no-tls.xxxxxx.clustercfg.memorydb.ap-northeast-1.amazonaws.com";
const port = 6379;

export const redis = new Cluster([{ host, port }], {
  dnsLookup: (address, callback) => callback(null, address),
});

await redis.set("abc", 1234)
var val = await redis.get("abc")
console.log(val)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment