Node-redis: ์ŠคํŠธ๋ฆฌ๋ฐ ์„œ๋ฒ„ ์‘๋‹ต

์— ๋งŒ๋“  2016๋…„ 12์›” 14์ผ  ยท  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. ๊ธฐ๋ณธ์ ์œผ๋กœ redis ๋ช…๋ น(์˜ˆ: SCAN, SSCAN, HSCAN, ZSCAN)์˜ ํ™”์ดํŠธ๋ฆฌ์ŠคํŠธ ์„ธํŠธ์— ๋Œ€ํ•ด node_redis ํด๋ผ์ด์–ธํŠธ์—์„œ ์ปค์„œ๋ฅผ ์ถ”์ƒํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@hossam-fares ๋‚˜๋Š” ๋ถ„๋ช…ํžˆ ๋น„์Šทํ•œ ๊ฒƒ์„ ๊ตฌํ˜„ํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค :+1:

@BridgeAR ๋ฉ‹์ ธ์š”, PR ์ž‘์—…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค

์ด๊ฒƒ์ด ๊ตฌํ˜„๋˜์—ˆ์Šต๋‹ˆ๊นŒ?

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰

๊ด€๋ จ ๋ฌธ์ œ

Mickael-van-der-Beek picture Mickael-van-der-Beek  ยท  6์ฝ”๋ฉ˜ํŠธ

Stono picture Stono  ยท  6์ฝ”๋ฉ˜ํŠธ

juriansluiman picture juriansluiman  ยท  3์ฝ”๋ฉ˜ํŠธ

yuany picture yuany  ยท  4์ฝ”๋ฉ˜ํŠธ

dotSlashLu picture dotSlashLu  ยท  5์ฝ”๋ฉ˜ํŠธ