Whether to use protobuf-net to serialize primitives before storing in Redis
c#, protobuf-net, redis, serialization, stackexchange.redis
Solution
Redis stores all values as binary strings, although there is IIRC some special casing for "strings" that, as ASCII, look exactly like integers. For a single primitive value, there isnt going to be any significant difference in terms of storage space, so if it is convenient, I would avoid adding an extra layer of protobuf-net. This may also allow SE.Redis to special-case the value in many cases, too - and it avoids a few extra allocations of things like `MemoryStream` or `byte[]`. It isn't going to be huge either way, but since they aren't buying you anything: why use them?
The question becomes more interesting when `T` is structured object data.
Problem
I am looking at implementing Redis for caching data in a ASP.Net web app. What I am wondering is, is it worth serializing certain types (string, bool, int, and other primitives) via Protobuf-net before storing in Redis, or will it be serialized anyway? I am mainly interested in speed of storage/retrieval, so I realise with certain strings, protobuf will make a difference by reducing network traffic, despite the tiny serialisation overhead. (And yes, I know that string is not a primitive) If it helps, I am using StackExchange.Redis.