本文整理汇总了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);
}
示例2: getRedisDb
export function getRedisDb() {
let client = createClient(6379, '127.0.0.1', {});
client.on("error", (err) => {
console.log("Error " + err);
});
return client;
}
示例3: getRedisClient
getRedisClient(): IRedisClient {
if (this.containerParams.redisClient === null) {
this.containerParams.redisClient = redis.createClient();
}
return this.containerParams.redisClient;
}
示例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,
}));
}
示例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');
}
});
}
}
示例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();
}
});
示例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 });
}
});
});
示例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;
};
示例9: constructor
/**
* Constructor
*/
constructor (options: IRedisOptions) {
super();
this._prefix = options.prefix || '';
this._client = redis.createClient(options);
}
示例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;
};
示例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;
}
示例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());
}
示例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
}
示例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();
}
示例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()
});
})