本文整理匯總了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);
});
});