本文整理汇总了TypeScript中ioredis.on函数的典型用法代码示例。如果您正苦于以下问题:TypeScript on函数的具体用法?TypeScript on怎么用?TypeScript on使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了on函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Promise
const useRedis = new Promise(resolve => {
redis.on('ready', () => {
resolve(true);
});
redis.on('error', err => {
resolve(false);
return redis.quit();
});
}).then(val => {
示例2: Redis
const redisHandler = (orm: {skip: boolean, config?: Redis.RedisOptions | string},
logger: Logger, callback: (err, ...args) => void) => {
if (orm.skip) return callback(void 0);
const cursor = new Redis(orm.config as Redis.RedisOptions);
cursor.on('error', err => {
logger.error(`Redis::error event - ${cursor['options']['host']}:${cursor['options']['port']} - ${err}`);
logger.error(err);
return callback(err); // TODO: Check if `callback` has been called
});
cursor.on('connect', () => {
logger.info(`Redis client connected to:\t ${cursor['options']['host']}:${cursor['options']['port']}`);
return callback(void 0, { connection: cursor });
});
};
示例3: redis
"use strict";
import * as escape from "escape-html";
import * as express from "express";
import { NextFunction } from "express-serve-static-core";
import * as redis from "ioredis";
import * as uuid from "uuid/v1";
import * as appConfig from "../utils/environment";
import * as errorHandler from "../utils/error.handler";
import { IImage } from "./image.schema";
const conf = appConfig.getConfig(process.env);
const redisClient = new redis(conf.redisPort, conf.redisHost);
redisClient.on("connect", function () {
console.log("connected");
});
/**
* Busca una imagen
*/
export interface IReadRequest extends express.Request {
image: IImage;
}
export function read(req: IReadRequest, res: express.Response) {
res.json(req.image);
}
/**
* @api {post} /image Guardar Imagen
* @apiName Guardar Imagen
* @apiGroup Imagen
示例4: Redis
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: function() { return false; },
showFriendlyErrorStack: true
})
var pub = new Redis();
redis.subscribe('news', 'music', function(err: any, count: any) {
// Now we are subscribed to both the 'news' and 'music' channels.
// `count` represents the number of channels we are currently subscribed to.
pub.publish('news', 'Hello world!');
pub.publish('music', 'Hello again!');
});
redis.on('message', function(channel: any, message: any) {
// Receive message Hello world! from channel news
// Receive message Hello again! from channel music
console.log('Receive message %s from channel %s', message, channel);
});
// There's also an event called 'messageBuffer', which is the same as 'message' except
// it returns buffers instead of strings.
redis.on('messageBuffer', function(channel: any, message: any) {
// Both `channel` and `message` are buffers.
});
示例5: Redis
return T.makeTask_(cb => {
const redis = new Redis(uri);
redis.on('ready', () => {
cb(null, redis);
});
});