Node-redis: Respuesta del servidor de transmisión

Creado en 14 dic. 2016  ·  6Comentarios  ·  Fuente: NodeRedis/node-redis

Hola, ¿es posible con node_redis transmitir la respuesta del servidor con comandos como HMGET o KEYS ?

Gracias.

Feature Request

Todos 6 comentarios

: +1: sería genial si tuviéramos una implementación para ello

@aletorrado Ya tenía una situación similar y quería transmitir desde HKEYS cmd
así que creé una secuencia legible usando HSCAN cmd, con esta implementación:

const redis = require('redis');
const connectionParams = {};

class HKeysReadable extends require('stream').Readable {
  constructor(key, chunkSize, opt) {
    opt = opt || {};
    opt.objectMode = true;
    super(opt);
    this._cursor = 0;
    this.key = key;
    this.chunkSize = chunkSize;
    this.client = redis.createClient(connectionParams);
  }

  _read() {
    if (this._cursor === '0') {
      this.push(null);
      return this.client.quit();
    }

    this.client.hscan(this.key, this._cursor, 'COUNT', this.chunkSize, (err, res) => {
        if (err) {
          this.push(null);
          this.client.quit();
          return process.nextTick(() => this.emit('error', err));
        }

        this._cursor = res[0];

        /**
         *
         SCAN returns value as an array of two values, the first value is the new cursor to use in the next call,
         the second value is an array of elements like: [key1, val1, key2, val2, key3, val3, .....]
         In this stream, we need the keys only so we reduce that array to get only the odd values which contain the keys

         */
        let keys = res[1].reduce((accumulator, val, index)=> {
          if (!(index % 2)) {
            accumulator.push(val);
          }

          return accumulator;
        }, []);

        if (keys.length > 0) {
          this.push(keys);
        }
      }
    );
  }
};

@BridgeAR ¿qué opinas? ¿Existe la posibilidad de adaptar una implementación similar en la biblioteca de Redis también?

Excelentes tarifas @ hossam. Básicamente, puede abstraer cursores de clientes node_redis , para un conjunto de comandos de redis incluidos en la lista blanca (es decir, SCAN, SSCAN, HSCAN, ZSCAN).

@ hossam-fares Definitivamente me gustaría que se implementara algo similar: +1:

@BridgeAR genial, trabajaré en un PR para eso

¿Se ha implementado esto?

¿Fue útil esta página
0 / 5 - 0 calificaciones

Temas relacionados

michaelwittig picture michaelwittig  ·  3Comentarios

juriansluiman picture juriansluiman  ·  3Comentarios

ghost picture ghost  ·  3Comentarios

Atala picture Atala  ·  3Comentarios

yuany picture yuany  ·  4Comentarios