Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store user defined objects using StackExchange.Redis?

I was able to do this in ServiceStack.redis by using,

IRedisTypedClient<ObjectName> myObj = redisClient.As<ObjectName>();

But I couldn't find any examples to do this in StackExchange.Redis.

Do I have to Serialize to JSON and then store them?

Thanx in advance.

like image 825
Gayan Jayasingha Avatar asked Aug 27 '14 20:08

Gayan Jayasingha


2 Answers

At the current time, SE.Redis does not attempt to offer serialisation - there are simply too many different ways of doing that. I'm rather of the opinion that the library should do one thing, not 7. It should be possible to add any hybrid serialisation etc concerns simply by extension methods or other plumbing/wrapping code, choosing any serialisation strategy you choose, and any library you choose.

like image 151
Marc Gravell Avatar answered Nov 13 '22 00:11

Marc Gravell


Simplest solution will be use json/binary/other serialization. More complex but more native - using redis "hashes" data type.

In first case i prefer protobuf library (it included by default to StackExchange.Redis.Extensions.Protobuf nuget package). But you can use json/binary/xml serialization if you need.

There is a good performance report about them all : https://medium.com/@maximn/serialization-performance-comparison-xml-binary-json-p-ad737545d227

like image 11
Nigrimmist Avatar answered Nov 13 '22 01:11

Nigrimmist