當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。