我正在尝试使用 npm 包将键值对插入到 Elasticache Redis 中@aws-sdk/client-elasticache
。
此实现的目的是存储带有 ID 的令牌。
这应该是一个 lambda 函数,所以我添加了一个层来使用这个 SDK,代码实现是这样的:
const { ElastiCacheClient } = require("@aws-sdk/client-elasticache");
const redisOptions = {
host: "host address",
port: PORT,
};
exports.handler = async (event) => {
const client = new ElastiCacheClient(redisOptions);
const params = { "tokenKey": "SomeTokenValue" };
try {
const data = await client.middlewareStack.add(params);
console.log("DATA: ", data); // this is undefined now
} catch (err) {
throw err;
}
};
当我 console.logclient
实例时,我看到:
ElastiCacheClient {
middlewareStack: {
add: [Function: add],
addRelativeTo: [Function: addRelativeTo],
clone: [Function: clone],
use: [Function: use],
remove: [Function: remove],
removeByTag: [Function: removeByTag],
concat: [Function: concat],
applyToStack: [Function: cloneTo],
resolve: [Function: resolve]
},
我无法将KVP插入redis,我在这里做错了什么?
PS
client.send(params)
抛出错误说send
不是函数。