Node-redis: Réponse du serveur de streaming

Créé le 14 déc. 2016  ·  6Commentaires  ·  Source: NodeRedis/node-redis

Salut, est-il possible avec node_redis de diffuser la réponse du serveur avec des commandes comme HMGET ou KEYS ?

Merci.

Feature Request

Tous les 6 commentaires

:+1: ce serait bien si nous avons une implémentation pour cela

@aletorrado J'ai déjà eu une situation similaire et je voulais diffuser à partir de HKEYS cmd
j'ai donc créé un flux lisible à l'aide de HSCAN cmd, avec cette implémentation :

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'en pensez-vous ? est-il possible d'adapter également une implémentation similaire dans la bibliothèque Redis ?

Super @hossam-fares. Fondamentalement, il peut abstraire les curseurs des clients node_redis , pour un ensemble de commandes redis sur liste blanche (c'est-à-dire SCAN, SSCAN, HSCAN, ZSCAN).

@hossam-fares J'aimerais vraiment que quelque chose de similaire soit mis en œuvre :+1:

@BridgeAR cool, je vais travailler sur un PR pour ça

Cela a-t-il été mis en œuvre ?

Cette page vous a été utile?
0 / 5 - 0 notes

Questions connexes

strumwolf picture strumwolf  ·  4Commentaires

Stono picture Stono  ·  6Commentaires

jackycchen picture jackycchen  ·  4Commentaires

Atala picture Atala  ·  3Commentaires

adamgajzlerowicz picture adamgajzlerowicz  ·  4Commentaires