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


TypeScript redis.createClient函数代码示例

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


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


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