[Azure] Redis cache fixes
Description of the original error encountered
The RedisCache
class is hard coded with CompressionCodec
. This codec is used for encoding and decoding purposes of key and values in redis cache.
The bug arises when the following sequence of steps takes place.
- Using atomic increment operation of redis cache will increment the value corresponding to the given key. Since redis cache will not have any data type, it will just increment the value assuming the value to be plain bytes (which it is not since we're using the compression codec)
- Using the get operation on the same key will result in EOFException as the decoding happens on the incremented value from the above step which assumed integer type/representation in the earlier step (which is the not the case since CompressionCodec will change the values from plain bytes to compressed bytes).
Gist of this problem: The problem arises from the issue that Redis has no data types and all values are just bytes while certain commands imply a particular type/representation.
Resolution
CompressionCodec
uses JSONCodec
, which will not change the plain bytes representation of the data stored in redis cache. Hence upon using JSONCodec, we get rid of the EOFException error arising when using get operation after increment operation.
However, there is no way we can provide custom codec to the existing redis cache method. Hence this MR in os core common adds ability to provide (or override) the codec that will be used for serialization and deserialization purposes in RedisCache. Link to the MR: osdu/platform/system/lib/core/os-core-common!148 (merged). Once the MR is merged in os core common, one can keep using the default codec (CompressionCodec) OR can override the codec as well as per the requirements if the need be.