-
Notifications
You must be signed in to change notification settings - Fork 165
Description
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?