本文整理汇总了TypeScript中ioredis.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
return async (...args) => {
const key = cacheKey + JSON.stringify(args);
const result = await redis.get(key);
let value: any;
let renewCache = true;
if (result) {
const cached = JSON.parse(result);
value = cached.value;
renewCache = isExpired(cached.at, timeMs);
}
if (!renewCache) return value;
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();
});
};
示例2: findByID
export function findByID(req: IFindByIdRequest, res: express.Response, next: NextFunction) {
const id = req.params.imageId;
redisClient.get(escape(id), function (err, reply) {
if (err) return errorHandler.handleError(res, err);
if (!reply) {
return errorHandler.sendError(res, errorHandler.ERROR_NOT_FOUND, "No se pudo cargar la imagen " + id);
}
req.image = {
id: escape(id),
image: reply
};
next();
});
}
示例3: test
test("Confirms user and clears key in redis", async () => {
const url = await createConfirmEmail(
process.env.TEST_HOST as string, // cast to string to satisfy typeScript
userId as string,
redis
);
// make get request to the url to get "ok" to signal that user was
// updated
const response = await fetch(url);
const text = await response.text();
expect(text).toEqual("ok");
const user = await User.findOne({ where: {id: userId} });
expect((user as User).confirmed).toBeTruthy();
const chunks = url.split('/');
const key = chunks[chunks.length - 1];
const value = await redis.get(key);
expect(value).toBeNull();
})
示例4: 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',
示例5: Redis
import * as Redis from "ioredis";
const redis = new Redis();
redis.set('foo', 'bar');
redis.get('foo', (err, result) => {
console.log(result);
});
// Or using a promise if the last argument isn't a function
redis.get('foo').then((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',
db: 0,
retryStrategy() { return false; },