Skip to content

[redis] support native binary storage #559

@cjpearson

Description

@cjpearson

Describe the feature

Currently the redis driver does not implement getItemRaw/setItemRaw. It uses the default method of serializeRawData + setItem.

Since ioredis can binary data, it should be unnecessary to encode it as base64. Directly setting a Buffer would have less overhead and be more space-efficient. However, there would be compatibility issues with existing data. Perhaps it could be implemented as an option or separate driver?

https://github.com/redis/ioredis#handle-binary-data

Here's an example implementation. It would still need to be updated to handle non-Buffer values.

async getItemRaw(key) {
  const value = await getRedisClient().getBuffer(p(key));
  return value ?? null;
},
async setItemRaw(key, value, tOptions) {
  if (value instanceof Uint8Array) {
    value = Buffer.from(value, value.byteOffset, value.byteLength)
  }
  const ttl = tOptions?.ttl ?? opts.ttl;
  if (ttl) {
    await getRedisClient().setBuffer(p(key), value, "EX", ttl);
  } else {
    await getRedisClient().setBuffer(p(key), value);
  }
},

This could perhaps be done with #528 and I think that would avoid the breaking aspects. For example setItemRaw could continue to base64 encode and save as a string, but setItem(k, v, { type: 'bytes'}), could save as binary.

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions