TheCloudlessSky / Harbour.RedisSessionStateStore

A Redis based SessionStateStoreProvider written in C# using ServiceStack.Redis.
MIT License
166 stars 76 forks source link

serialize type question #18

Closed uliian closed 1 year ago

uliian commented 10 years ago

I think ,now,Harbour.RedisSessionStateStore,Get/Set Session items use FCL Binary serialize method.That will let it bound with assembly,hard to share with not same assembly. In my opinion,we will store json to Redis and store items type to Redis.like this:

    private void Set<T>(string key, T o)
    {
        using (IRedisClient client = RedisPool.redisPool.GetClient())
        {
            client.SetEntryInHash(_sessionId, key+"Type", o.GetType().ToString());
            client.SetEntryInHash(_sessionId, key + "Data", Newtonsoft.Json.JsonConvert.SerializeObject(o));
            client.ExpireEntryIn(_sessionId, _expiresIn);
        }
    }

It can use to any assembly.and session can work to not same appDomain.can be provide SSO!

my English very bad~T.T

TheCloudlessSky commented 10 years ago

Hey @uliian!

I think I was able to figure out what you mean :smile:. Do you mean you would like to control the serialization of the items? I was thinking of adding this lately. Right now, binary serialization is done using .NET's SessionStateItemCollection.

If I did allow customizing the serialization, I'd open it up similar to how I do it in the RedisTempData I created.

I know the Azure session state store provider uses the NetDataContractSerializer. The default serializer would have to stay the same, but it would allow you to write an adapter to use what ever serializer you'd like.

What do you think about opening this up to allow people to customize this?

uliian commented 10 years ago

Yes I think can customize is a good choice.But in my project ,I use other method to resolve share data problem:Use other data container extend session in BaseController or BasePage named ExtStore property.because in different application share data always have data type problem.So,I extend session ,use session id to store some user data,program can use strong type to get data,it can get json too.I think it more free .