Node-redis: Ответ потокового сервера

Созданный на 14 дек. 2016  ·  6Комментарии  ·  Источник: NodeRedis/node-redis

Привет, возможно с помощью node_redis передать ответ сервера с помощью таких команд, как HMGET или KEYS ?

Спасибо.

Feature Request

Все 6 Комментарий

: +1: было бы здорово, если бы у нас была реализация для этого

@aletorrado У меня уже была похожая ситуация, и я хотел стримить из HKEYS cmd
поэтому я создал читаемый поток с помощью HSCAN cmd с этой реализацией:

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 что ты думаешь? есть ли возможность адаптировать подобную реализацию и в библиотеке Redis?

Отличные @ hossam-fares. В основном он может абстрагировать курсоры от клиентов node_redis для набора команд redis из белого списка (например, SCAN, SSCAN, HSCAN, ZSCAN).

@ hossam-fares Я бы определенно хотел реализовать что-то подобное: +1:

@BridgeAR круто, буду работать над пиаром для него

Это было реализовано?

Была ли эта страница полезной?
0 / 5 - 0 рейтинги

Смежные вопросы

jackycchen picture jackycchen  ·  4Комментарии

juriansluiman picture juriansluiman  ·  3Комментарии

betimer picture betimer  ·  5Комментарии

strumwolf picture strumwolf  ·  4Комментарии

dotSlashLu picture dotSlashLu  ·  5Комментарии