Skip to content

Support Uint8Array values for zero-copy transfer to worker_threads #3106

Description

@akaNightmare

Motivation

Currently, Redis values are returned as Buffer, which requires manual conversion or copying when sending data to worker_threads.
To enable zero-copy transfer, it would be great to support Uint8Array as a return type.
Internally, the implementation may use new TextEncoder().encode(redisRes) or similar logic when encoding strings to Uint8Array.

Basic Code Example

const redis = await createClient({ url: 'redis://localhost:7777' })
        .on("error", (err) => console.log("Redis Client Error", err))
        .connect();

    const rawData = await fs.readFile('./package.json');

    await redis.set('__foo1', rawData);

    const res = await redis.withTypeMapping({
        [RESP_TYPES.BLOB_STRING]: Uint8Array,
    }).get('__foo1');

    worker.postMessage(res, [res.buffer]);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions