go-redis/cache

How to handle versioning of structs

suren4Kites opened this issue · 1 comments

Hi,

I am trying to cache a go struct, am setting the expiry as 1 day.
Lets say my struct is {a:"aa", b:"bb"} and the key is K1, its expiry is 1 day. But I changed the struct to have one field, let's say {a:"aa", b:"bb", c:"cc"}, if the Key is not expired, it will not get updated since the same key.
I want to have an option to identify the version of struct change, before get or set cache.
Please let me know if there is any way.

The problem here is that such functionality would require cooperation with library that encodes the struct, e.g. https://github.com/vmihailenco/msgpack or encoding/json. encoding/json would have to provide list of fields it used to encode the struct and/or some versioning key. That is a lot of trouble in order to solve this problem.