本文整理匯總了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',