csredis icon indicating copy to clipboard operation
csredis copied to clipboard

Thread CurrentCulture csredis hash exception with docker container

Open megadotnet opened this issue 3 years ago • 0 comments

.netcore 2.2, csredis 3.6.6

Exception:

System.FormatException: Input string was not in a correct format. at CSRedis.CSRedisClient.GetAndExecuteAsync[T](RedisClientPool pool, Func2 handerAsync, Int32 jump, Int32 errtimes) at CSRedis.CSRedisClient.ExecuteScalarAsync[T](String key, Func3 handerAsync) at CSRedis.CSRedisClient.HGetAsync[T](String key, String field) at WebredisTest.Controllers.ValuesController.Get() in

Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:3.1 COPY . /app WORKDIR /app ENV ASPNETCORE_URLS=http://*:5000 TZ=Asia/Shanghai ENTRYPOINT ["dotnet", "WebredisTest.dll"]

Code:

[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
    public ValuesController()
    {
        RedisHelper.Initialization(new CSRedis.CSRedisClient("192.168.103:6379,password=,defaultDatabase=6"));
    }

    // GET api/values
    [HttpGet]
    public async Task<string> Get()
    {
        return await hashtest("ar");
    }

    // GET api/values/5
    [HttpGet("{id}")]
    public async Task<string> Get(int id)
    {
        return await hashtest("en");
    }

    private async Task<string> hashtest(string lang)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
        string key = Thread.CurrentThread.CurrentCulture.EnglishName + "testRedisHash";
        await RedisHelper.HSetAsync(key, "1", "1");
        return await RedisHelper.HGetAsync<string>(key, "2");
    }

}

megadotnet avatar Oct 26 '21 14:10 megadotnet