当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ioredis.get函数代码示例

本文整理汇总了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();
    });
  };
开发者ID:WordToken,项目名称:voice-web,代码行数:35,代码来源:lazy-cache.ts

示例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();
  });
}
开发者ID:maticorv,项目名称:mascotas2018_foro,代码行数:17,代码来源:image.service.ts

示例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();
    
    })
开发者ID:itaygolan,项目名称:GraphQL-Typescript-Server,代码行数:24,代码来源:createEmailLink.test.ts

示例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',
开发者ID:Root-Core,项目名称:DefinitelyTyped,代码行数:29,代码来源:ioredis-tests.ts

示例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; },
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:ioredis-tests.ts


注:本文中的ioredis.get函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。