Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import _ from 'lodash';
- import Redis from 'ioredis';
- import { redis as cfg } from './environment';
- import logger from './logger';
- Redis.Command.setReplyTransformer('zrevrangebyscore', result => {
- const data = [];
- for (let i = 0; i < result.length; i += 2) {
- const object = {
- username: result[i],
- points: parseInt(result[i + 1])
- }
- data.push(object)
- }
- return data;
- });
- Redis.Command.setReplyTransformer('zscore', result => {
- return _.isNumber(result) ? result : parseInt(result, 10);
- });
- Redis.Command.setReplyTransformer('zrem', result => {
- return result === 1;
- });
- Redis.Command.setReplyTransformer('zincrby', result => {
- return parseInt(result, 10);
- });
- /**
- * General stuff + subscribe connection
- * use redis.pipeline if > 5 commands
- */
- const redis = new Redis({
- port: cfg.port,
- host: cfg.host,
- password: cfg.password,
- db: cfg.db
- });
- export default redis;
- redis.on('connect', () => {
- logger.info('Established a connection to redis');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement