Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Serialization on SetAddSync #447

Open
dotsad opened this issue Jan 15, 2022 · 3 comments
Open

Incorrect Serialization on SetAddSync #447

dotsad opened this issue Jan 15, 2022 · 3 comments

Comments

@dotsad
Copy link

dotsad commented Jan 15, 2022

Describe the bug
.SetAddAsync does not correctly serializes and adds single string or string[] to redis cache. Single items are added with "quotes" around them and multiple items are added as a single string array item.

To Reproduce
Consider using StackExchange.Redis.Extensions version 8.0.3

    public class RedisController : Controller
    {
        public IRedisClient _redisCacheClient { get; }
        private string _version = "8.0.3";

        public RedisController(IRedisClient redisCacheClient)
        {
            _redisCacheClient = redisCacheClient;
        }

        [HttpGet]
        [Route("Single-IRedisCacheClient")]
        public async Task<IActionResult> AddSingleToSet()
        {
            var db = _redisCacheClient.GetDefaultDatabase();
            RedisKey key = $"{_version}-IRedisCacheClient-peopleSingle";
            await db.SetAddAsync(key, "Alexis", CommandFlags.None);
            return Ok();
        }

        [HttpGet]
        [Route("Multiple-IRedisCacheClient")]
        public async Task<IActionResult> AddMultipleToSet()
        {
            var db = _redisCacheClient.GetDefaultDatabase();
            RedisKey key = $"{_version}-IRedisCacheClient-peopleMultiple";
            string[] redisValue1 = new string[] { "Nika", "Allah", "Booka" }; //.Select(key => (RedisValue)key).ToArray();
            var dd = await db.SetAddAsync(key, redisValue1, StackExchange.Redis.CommandFlags.None);
            return Ok();
        }
    }

This is the output we get:
image

Expected behavior
Using StackExchange.Redis.Extensions version 5.5.0 with obsolete ICacheClient client :

    public class RedisController : Controller
    {
        public ICacheClient _cacheClient { get; }
        private string _version = "5.5.0";

        public RedisController(ICacheClient cacheClient)
        {
            _cacheClient = cacheClient;
        }

        [HttpGet]
        [Route("Single-ICacheClient")]
        public async Task<IActionResult> AddSingleToSetIRedisCacheClient()
        {
            var db = _cacheClient.Database;
            RedisKey key = $"{_version}-ICacheClient-peopleSingle";
            await db.SetAddAsync(key, "Alexis", CommandFlags.None);
            return Ok();
        }

        [HttpGet]
        [Route("Multiple-ICacheClient")]
        public async Task<IActionResult> AddMultipleToSetIRedisCacheClient()
        {
            var db = _cacheClient.Database;
            RedisKey key = $"{_version}-ICacheClient-peopleMultiple";
            RedisValue[] redisValue = new string[] { "Alexis", "Peter", "Irina" }.Select(key => (RedisValue)key).ToArray();
            var dd = await db.SetAddAsync(key, redisValue, StackExchange.Redis.CommandFlags.None);
            return Ok();
        }
    }

We get correct redis cache entries:
image

Desktop (please complete the following information):

  • OS: Windws 10
  • Runtime version [.NET Framework, .NET 6.0]
  • Version [e.g. 8.0.3]
@imperugo
Copy link
Owner

Hi @dotsad what serializer are you using?

@dotsad
Copy link
Author

dotsad commented Jan 17, 2022

Hi @dotsad what serializer are you using?

It doesn't matter, either system.text or newtonsoft, both serialize string as an object in quotes. There should be a separate method that takes a string and not serialize it. Also regarding string[], it doesn't work as well

@AntonSmolkov
Copy link

The same here:
image
First row is created via ITransaction (#158) the second one via .SetAddAsync().

Versions:

StackExchange.Redis.Extensions.Core 10.0.2
StackExchange.Redis.Extensions.System.Text.Json 10.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants