skip to Main Content

Seems most commands allow for buffers to be returned using { returnBuffers: true }
This however doesn’t seem to work for the various scan methods. Particularly, I’m trying to use hScanIterator.

Is there any way to return buffers using hScanIterator?

2

Answers


  1. I did a spelunk into the code and it looks like it doesn’t support it. That said, I think it should. I’d open an issue and ask for it.

    As a workaround, the strings that are returned are parsable to bytes. They use a C-style escaping syntax. I tried to find a library for Node.js that would convert them to bytes to no avail but it certainly wouldn’t be hard to write one. The code that escapes these string in Redis (at least I think this is the code) shows you what you would need to look for and convert in the string.

    Perhaps not the answer you were hoping for, but probably as good as it will get until the feature is added. 😉

    Login or Signup to reply.
  2. The built-in scan iterator methods does not support the returnBuffer flag (although they should). In the mean time you can implement the iterator youself:

    function* hScanBufferIterator(client, key, options) {
      let cursor = 0;
      do {
        const reply = await client.hScan(
          client.commandOptions({ returnBuffers: true }),
          key,
          cursor,
          options
        );
        cursor = reply.cursor;
        for (const tuple of reply.tuples) {
          yield tuple;
        }
      } while (cursor !== 0);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search