本文整理汇总了TypeScript中ioredis.set函数的典型用法代码示例。如果您正苦于以下问题:TypeScript set函数的具体用法?TypeScript set怎么用?TypeScript set使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: create
export function create(req: express.Request, res: express.Response) {
const image: IImage = {
id: uuid(),
image: req.body.image
};
redisClient.set(image.id, image.image, function (err: any, reply: any) {
if (err) {
return errorHandler.handleError(res, err);
}
res.json({ id: image.id });
});
}
示例2: Promise
return new Promise(async resolve => {
const lock = await redlock.lock(
key + '-lock',
1000 * 60 * 60 * 3 /*3 minutes*/
);
const result = await redis.get(key);
if (result) {
const cached = JSON.parse(result);
renewCache = isExpired(cached.at, timeMs);
resolve(cached.value);
}
if (renewCache) {
value = await f(...args);
await redis.set(key, JSON.stringify({ at: Date.now(), value }));
resolve(value);
}
await lock.unlock();
});
示例3: Redis
import * as Redis from "ioredis";
var redis = new Redis();
redis.set('foo', 'bar');
redis.get('foo', function(err, result) {
console.log(result);
});
// Or using a promise if the last argument isn't a function
redis.get('foo').then(function(result: any) {
console.log(result);
});
// Arguments to commands are flattened, so the following are the same:
redis.sadd('set', 1, 3, 5, 7);
redis.sadd('set', [1, 3, 5, 7]);
// All arguments are passed directly to the redis server:
redis.set('key', 100, 'EX', 10);
new Redis() // Connect to 127.0.0.1:6379
new Redis(6380) // 127.0.0.1:6380
new Redis(6379, '192.168.1.1') // 192.168.1.1:6379
new Redis('/tmp/redis.sock')
new Redis({
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
family: 4, // 4 (IPv4) or 6 (IPv6)
password: 'auth',