Node-redis: تدفق استجابة الخادم

تم إنشاؤها على ١٤ ديسمبر ٢٠١٦  ·  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 التقييمات