-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(redis): opt-in raw
support
#561
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #561 +/- ##
==========================================
- Coverage 65.05% 60.07% -4.98%
==========================================
Files 39 42 +3
Lines 4055 3702 -353
Branches 487 615 +128
==========================================
- Hits 2638 2224 -414
- Misses 1408 1467 +59
- Partials 9 11 +2 ☔ View full report in Codecov by Sentry. |
saveRawAsBinary
driver optionraw
support
@@ -72,7 +72,7 @@ const storage = createStorage({ | |||
- `cluster`: List of redis nodes to use for cluster mode. Takes precedence over `url` and `host` options. | |||
- `clusterOptions`: Options to use for cluster mode. | |||
- `ttl`: Default TTL for all items in **seconds**. | |||
- `useRaw`: If enabled, `getItemRaw` and `setItemRaw` will use binary data instead of base64 encoded strings. (this option will be enabled by default in the next major version.) | |||
- `raw`: If enabled, `getItemRaw` and `setItemRaw` will use binary data instead of base64 encoded strings. (this option will be enabled by default in the next major version.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest something like binary
/useBinary
here. I think it makes the effect a bit more clear because it changes how raw data is stored, but does not enable/disable the ability to save raw data. Or it could be inverted to base64
so in the future the default value can be false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that in general binary
could be more describing than raw
. In the context of unstorage, we call binary-compatible feature raw
which was the reason I was thinking to use this.
Considering it is for short-term solution, are you happy we go with raw?
(Also check fb2977a, I have extended normalization)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extending normalization to additional variants of TypedArray makes sense, but it should only allow for binary data and continue to throw when other data is passed. Otherwise it would lead to some unexpected behavior as you save an object but get a Buffer back.
That's also why I think the different naming is helpful. binary
means that setItemRaw
accepts binary and getItemRaw
returns binary. Whereas the existing raw
behavior accepts binary and other things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is consistent with generic unstorage.*raw*
interface behavior -- happy to change it in the future (so ALL calls to setItemRaw
will be restricted to accept binary only not objects) but normally, users should use the same key
either for raw or non-raw purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm would it be possible to add an additional option in that case? Either on the driver or the method? What I'm looking for is a way to save binary data and ensure it is binary and saved as binary and when getting, that I get a Buffer in return.
My assumption is that is how getItem(key, { type: 'bytes'})
/setItem(key, value, { type: 'bytes'})
would work in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes exactly for type: 'bytes'
we can get strict.
Currently, if someone passes a string to setItemRaw
, getItemRaw
gives a Buffer
representation of Utf8
bytes which isn't that odd ,is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's what I find a bit unexpected 😅
Do you think there would be an issue if we added type: 'bytes'
as a method option here? It would be just for the redis driver at the moment, but done in a forward compatible manner.
Or is it better to use something else and save that wording for later
Resolves #559
This change adds a new
saveRawAsBinary
option to the redis driver. When enabled, the driver will use thesetBuffer
andgetBuffer
methods ofioredis
to directly saveBuffer
s rather than base64 encoding and saving as a string. The option is not enabled by default as that would be a backwards incompatible change.When #528 is implemented, this could be made the default for
{type: 'bytes'}
. (Perhaps thensaveBytesAsBinary
is a better name?) It would also be possible to drop the base64 encoding entirely and instead allow users to manually encode and save as{ type: 'text' }
.