• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript redis.createClient函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中redis.createClient函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createClient函数的具体用法?TypeScript createClient怎么用?TypeScript createClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了createClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: constructor

  constructor(events: Events, config: any, logger) {
    if (!logger) {
      throw new Error('Missing logger config or object');
    }
    if (_.isNil(events)) {
      logger.error('No Kafka client was provided, offsets will not be stored to redis');
      return;
    }

    this.config = config;
    this.logger = logger;

    if (!(this.config.get('events'))
      || !(this.config.get('events:kafka'))
      || !(this.config.get('events:kafka:topics'))) {
      throw new Error('Kafka events configuration was not provided.');
    }

    this.kafkaEvents = events;
    if (this.config.get('redis')) {
      const redisConfig = this.config.get('redis');
      if (_.has(redisConfig, 'db-indexes.db-offsetStore')) {
        redisConfig.db = _.get(redisConfig, 'db-indexes.db-offsetStore');
      }
      this.redisClient = redis.createClient(redisConfig);
    }
    this.topics = {};
    this.timerID = [];
    setTimeout(this.updateTopicOffsets.bind(this), 5000);
  }
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:30,代码来源:index.ts


示例2: getRedisDb

export function getRedisDb() {
    let client = createClient(6379, '127.0.0.1', {});
    client.on("error",  (err) => {
        console.log("Error " + err);
    });
    return client;
}
开发者ID:cclient,项目名称:typescriptjob,代码行数:7,代码来源:redis.ts


示例3: getRedisClient

    getRedisClient(): IRedisClient {
        if (this.containerParams.redisClient === null) {
            this.containerParams.redisClient = redis.createClient();
        }

        return this.containerParams.redisClient;
    }
开发者ID:kamilbiela,项目名称:auth360-backend,代码行数:7,代码来源:ServiceContainer.ts


示例4: setupSession

function setupSession(app: express.Express, config: IExpressConfig) {
  // tslint:disable-next-line: variable-name
  const RedisStore = connectRedis(expressSession);
  const redis_client = redis.createClient(config.redis_port || 6379, config.redis_host || '127.0.0.1');
  const session_store = new RedisStore({
    client: redis_client,
    pass: config.redis_password,
    ttl: config.session_ttl,
  });
  session_store.on('disconnect', () => {
    console.log('RedisStore for express is disconnected. Exit the process...');
    setTimeout(() => {
      process.exit(0);
    }, 1000);
  });
  app.use(expressSession({
    cookie: {
      domain: config.session_domain,
      maxAge: config.session_ttl * 1000,
    },
    name: config.session_name,
    resave: true, // session expire를 초기로 돌리기 위해서 매번 다시 저장한다
    saveUninitialized: config.session_save_uninitialized || false,
    secret: config.session_secret,
    store: session_store,
  }));
}
开发者ID:croquiscom,项目名称:Crary-Node,代码行数:27,代码来源:create_app.ts


示例5: constructor

	constructor(namespace: string, isReceveMode: boolean, redisOptions?: {host: string, port: number}) {
		super();
		this.namespace = namespace;
		this.isReceveMode = isReceveMode;
		this.redis = redis.createClient(redisOptions || { host: 'localhost', port: 6379 });
		this.redis.on('error', (err) => {
			throw new Error(`[RedisEventEmitter] ${String(err)}`);
		});
		if (this.isReceveMode) {
			this.redis.on('message', (namespace, json) => {
				let event;
				try {
					event = JSON.parse(json);
				}
				catch (err) {
					console.warn('recieved redis event is not json format.');
					return;
				}
				if (event.event == null || event.data == null) {
					return;
				}
				super.emit(event.event, event.data);
			});
			this.redis.subscribe(this.namespace, (err) => {
				if (err) {
					throw new Error('[RedisEventEmitter] failed to subscribe');
				}
			});
		}
	}
开发者ID:Frost-Dev,项目名称:Frost,代码行数:30,代码来源:RedisEventEmitter.ts


示例6: async

	ws.on('request', async (request) => {
		const connection = request.accept();

		const user = await authenticate(connection);

		// Connect to Redis
		const subscriber = redis.createClient(
			config.redis.port, config.redis.host);

		connection.on('close', () => {
			subscriber.unsubscribe();
			subscriber.quit();
		});

		const channel =
			request.resourceURL.pathname === '/' ? homeStream :
			request.resourceURL.pathname === '/messaging' ? messagingStream :
			null;

		if (channel !== null) {
			channel(request, connection, subscriber, user);
		} else {
			connection.close();
		}
	});
开发者ID:syuilo,项目名称:misskey-core,代码行数:25,代码来源:streaming.ts


示例7: Promise

  return new Promise((resolve) => {
    let isRedisLoaded = false;

    if (!cacheEnabled) {
      return resolve({ cacheEnabled, client: null });
    }

    // delete password key if it's value is null
    if (config.password === null) {
      delete config.password;
    }
    const client = redis.createClient(config);

    client.on('ready', () => {
      logger.info('App connected with redis server');

      if (!isRedisLoaded) {
        isRedisLoaded = true;
        return resolve({ cacheEnabled, client });
      }
    });

    client.on('error', (err) => {
      logger.error('Redis:', err);
      // Only throw an error if cache was enabled in config but were unable to load it properly
      if (!isRedisLoaded) {
        isRedisLoaded = true;
        return resolve({ cacheEnabled, client: null });
      }
    });
  });
开发者ID:RiseVision,项目名称:rise-node,代码行数:31,代码来源:cache.ts


示例8: getClient

function getClient(options) {
  if (!client || client.connected == false) {
    if (options == null) {
      options = sails.config.redis;
    }
    options.retry_strategy = (ret):any => {
      if (ret.error.code === 'ECONNREFUSED') {
        // End reconnecting on a specific error and flush all commands with a individual error
        return new Error('The server refused the connection');
      }
      if (ret.total_retry_time > 1000 * 10) {
        // End reconnecting after a specific timeout and flush all commands with a individual error
        return new Error('Retry time exhausted');
      }
      if (ret.times_connected > 10) {
        // End reconnecting with built in error
        return new Error('Connected fail for more than 10 times');
      }
      // reconnect after
      return Math.max(ret.attempt * 100, 1000);
    }

    client = redis.createClient(options);

    client.on("error", (e) => {
      console.error(e);
    });
  }

  return client;
};
开发者ID:martin-liu,项目名称:m-sails,代码行数:31,代码来源:Redis.ts


示例9: constructor

	/**
	 * Constructor
	 */
	constructor (options: IRedisOptions) {

		super();

		this._prefix = options.prefix || '';
		this._client = redis.createClient(options);

	}
开发者ID:AdExchangeGrp,项目名称:aeg-redis,代码行数:11,代码来源:client.ts


示例10: default

export default (config:any) => {

    let client:any = createClient(config.redis.port,config.redis.host);

    client.on("error", (err)=> {
        console.log(`Redis Error ${err}`);
    });
    return client;
};
开发者ID:khacthanh244,项目名称:mocha,代码行数:9,代码来源:dbredis.ts


示例11: createClient

function createClient() {
  const redisCli = redis.createClient(redisUrl.port, redisUrl.hostname);
  redisCli.auth(redisUrl.auth.split(":")[1]);

  redisCli.on("error", function (err) {
    console.log("REDIS ERROR - " + err);
  });

  return redisCli;
}
开发者ID:odetown,项目名称:golfdraft,代码行数:10,代码来源:redis.ts


示例12: f

    static doWithRedisClient<T>(f: (c: any) => Promise<any>) {
        const config = RedisAsync.redisConfig;
        const client: any = redis.createClient({
            host: config.host,
            port: config.port,
            db: config.dbNumber,
            auth_pass: config.password
        } as redis.ClientOpts);

        return f(client).finally(() => client.quit());
    }
开发者ID:itsuryev,项目名称:tp-oauth-server,代码行数:11,代码来源:redisAsync.ts


示例13: initRedisClient

export function initRedisClient(opts: RedisConnectionOptions) {
  if (opts instanceof redis.RedisClient) {
    return opts
  }
  if (typeof opts === "string") {
    opts = { url: opts }
  }
  const r = redis.createClient(opts)
  console.debug("Connected to redis:", (r as any).address)
  return r
}
开发者ID:dianpeng,项目名称:fly,代码行数:11,代码来源:redis_adapter.ts


示例14: Init

export function Init() {

  let RedisClient = redis.createClient();

  RedisClient.sadd("name-list",
    "Edsger Dijkstra",
    "Donald Knuth",
    "Alan Turing",
    "Grace Hopper",
    redis.print);

  RedisClient.quit();
}
开发者ID:kamilsherco,项目名称:stock-exchange-predictor,代码行数:13,代码来源:redis.ts


示例15: Promise

 return new Promise((resolve, reject) => {
     _client = redis.createClient(nconf.get("redis"));
     _client
         .on("error", (err) => {
             console.error(chalk.red("Redis connection crushed!"));
             console.log(err);
             throw err;
         })
         .once("ready", () => {
             console.log(chalk.green("Connected to Redis..."));
             resolve()
         });
 })
开发者ID:cm0s,项目名称:mea2n,代码行数:13,代码来源:redis_conf.ts


示例16: Init

export function Init() {

  const RedisClient = redis.createClient();

  RedisClient.sadd('name-list',
    'Edsger Dijkstra',
    'Donald Knuth',
    'Alan Turing',
    'Grace Hopper',
    redis.print);

  RedisClient.quit();
}
开发者ID:vyakymenko,项目名称:angular2-seed-express,代码行数:13,代码来源:redis.ts


示例17: Promise

		return new Promise((resolve) => {
			this.db = redis.createClient(this.settings.redis.port, this.settings.redis.host, this.settings.redis.options);

			this.db.on('ready', () => {
				Log.success('Redis', 'Connected to Redis.')
				this.db.select(this.settings.redis.db);
				resolve();
			})

			this.db.on('error', (error) => {
				Log.fatal('Redis', 'Something broke.')
				console.log(error);
			})
		})
开发者ID:Mikuia,项目名称:Mikuia,代码行数:14,代码来源:mikuia.ts


示例18: getMostPopularItems

            async getMostPopularItems(req:string,res:string) : Promise<string> {
                var jwt = res.locals.jwt;
                
                console.log(jwt);
                const ssoService:SSO.sso = new SSO.sso();

                /*
                let brandMap: { [id: string] : string; } = {};
                brandMap['Postpaid'] = 'GOLD';
                brandMap['Prepaid'] = 'BUDDY';
                brandMap['BroPostpaid'] = 'PLUGIT';
                brandMap['BroPostpaidShareIt'] = 'SHAREIT';
                brandMap['BroPrepaid'] = 'SPBRO';
                brandMap['PostpaidServiceUnit'] = 'SU';
                brandMap['Infinity'] = 'INFINITY';
                brandMap['TalkNText'] = 'TNT';
               */
                console.log('request: ' + req.query.brands);

                console.log('redis_url: ' + process.env.REDIS_URL);
                let client = redis.createClient(process.env.REDIS_URL);
                console.log('after redis_url');

                let promise: Promise<string> = new Promise((resolve, reject) => {
                    let brands = req.query.brands.split(',');
                    let keys = brands.map(brand => 'catalogItems:' + brand);
                    client.sunion(keys, (err, ids) => {
                        if (!err) {
                            client.get('catalogs:all', (err, catalogString) => {
                                let catalogs = JSON.parse(catalogString);
                                client.zrevrange(['mostpopular', 1, -1], (err, list) => {
                                    list = catalogs.data.filter(catalog => list.indexOf(catalog.catProductNo) > -1).map(e => e.catProductNo);
                                    resolve(list);
                                });
                            });
                        } else {
                            reject(err);
                        }
                    });
                });
                promise.then(
                    result => {
                        res.json(result);
                    }, err => {
                        console.log('error');
                    }
                );
            }
开发者ID:christoperhansaccenture,项目名称:smart-debug,代码行数:48,代码来源:reward.controller.ts


示例19:

    (req:any, res:any, next:any) => {

      let RedisClient = redis.createClient(),
          request = req.body;
          // request = JSON.parse(req.body);

      RedisClient.sadd('name-list', request.name,
        (err:any, replies:any) => {
          console.log(`
          Reply: ${replies}.`);

          res.json({success: true});
        });

      RedisClient.quit();
    });
开发者ID:kamilsherco,项目名称:stock-exchange-predictor,代码行数:16,代码来源:name.list.ts


示例20: constructor

 constructor(options: StoreOptions) {
   options.retry_strategy = options.retry_strategy || function (params) {
     if (params.error && params.error.code === 'ECONNREFUSED') {
       logger.error('Session redis connect failed, You can omit redis config in .env to resolve this');
       throw params.error;
     }
     if (params.attempt > 3) {
       throw params.error;
     }
     return params.attempt * 100;
   };
   this.client = options.client || redis.createClient(options);
   this.promiseGet = promisify(this.client.get.bind(this.client));
   this.promiseSet = promisify(this.client.setex.bind(this.client));
   this.promiseDel = promisify(this.client.del.bind(this.client));
 }
开发者ID:whosesmile,项目名称:koa-scaffold,代码行数:16,代码来源:store.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript redis.RedisClient类代码示例发布时间:2022-05-25
下一篇:
TypeScript RectRenderer.create函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap