StackExchange.Redis.Extensions icon indicating copy to clipboard operation
StackExchange.Redis.Extensions copied to clipboard

ISerializer,IRedisDatabase Non-generic Enhance

Open oTcom opened this issue 5 years ago • 5 comments

Hi@imperugo Let me describe the usage scenario.

GetAsync (cachekey) The return type is JObject, JDocment..., I need to specify the value return type.

Use GetAsync(cachekey, typeof(MyClass)) to return the type I want,.

//Now I have to do this to get the specified type.

var redisVlue = await _redisCacheClient.Db0.Database.StringGetAsync(cacheKey);
cacheValue = redisVlue.HasValue ? JsonSerializer.Deserialize(redisVlue, returnType) : cacheValue;

The test code is used to illustrate the usage scenarios for enhancing this function.

oTcom avatar Sep 22 '20 14:09 oTcom

ubuntu-latest build failed, can you try again.

oTcom avatar Sep 23 '20 04:09 oTcom

Hi @oTcom I don't understand the need. GetAsync<object>(...) isn't enought?

imperugo avatar Nov 09 '20 08:11 imperugo

Hi @imperugo Thank you for coming back.

GetAsync<object>(...)

The return type is JObject, JDocment.
I can only get object types,So you cannot use generic methods.

oTcom avatar Nov 09 '20 08:11 oTcom

What about a Custom Serializer that doesn't return JObject instead of that? Morver why you prefer object instead of T?

imperugo avatar Nov 09 '20 08:11 imperugo

I am using dynamic proxy method to intercept. In this scenario, only the type of the object can be obtained, and the specific T cannot be obtained.

oTcom avatar Nov 09 '20 08:11 oTcom