Typecasting data when inserting into Redis #22
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently when inserting a value into redis using a typed data structure - the value is serialized to redis based on its type, and not the type of the data structure.
As a result - it is possble to insert data that can not be read out again. For example, following the example in the readme:
I get
ArgumentError (invalid xmlschema format: "2021-03-02")
when trying to read the members out of Redis.In addition to this - if you inserted values into a unique list/set that didn't match the correct type of the unique set - then they are stored in redis as different values but then converted to be the same value when retrieved.
For example:
which is an unexpected result.
This PR uses ActiveModel::Types to convert perform serialization to redis and casting from the redis stored values. Some of these needed to be slightly different from the existing types as the storage (Redis) doesn't know how to store the same types of data as the relational databases.
An alternative to this approach would be to raise an error if the data passed in did not match the type on the data structure - but I think that casting similar to Active Record would provide a nicer experience.