首页 > 解决方案 > Redis 突然没有响应(在 docker 上)

问题描述

我在 docker (Centos Linux) 上使用 Redis。它运行正常并且可以正常工作几天或几周,但有时会突然停止工作。docker 容器已启动,我可以浏览它的文件。但是,它不响应redis-clibash 命令GetAsync以及SetAsync使用 IDistributedCache 接口或任何其他命令实现的 StackExchange.Redis 包中的方法。我通过以下命令运行 Redis 容器:

docker run --name x-redis -p 6379:6379 -d redis redis-server --appendonly yes

这是我的 docker 日志文件的最新信息:

{"log":"1:S 19 Feb 2020 04:06:08.957 * Master replied to PING, replication can continue...\n","stream":"stdout","time":"2020-02-19T04:06:08.958110011Z"}
{"log":"1:S 19 Feb 2020 04:06:09.408 * Trying a partial resynchronization (request 1e9525bb8323b08b0d258e78ff5d33107da9c:1).\n","stream":"stdout","time":"2020-02-19T04:06:09.40838749Z"}
{"log":"1:S 19 Feb 2020 04:06:09.633 * Full resync from master: ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ:0\n","stream":"stdout","time":"2020-02-19T04:06:09.633986888Z"}
{"log":"1:S 19 Feb 2020 04:06:09.633 * Discarding previously cached master state.\n","stream":"stdout","time":"2020-02-19T04:06:09.634015966Z"}
{"log":"1:S 19 Feb 2020 04:06:09.634 * MASTER \u003c-\u003e REPLICA sync: receiving 42680 bytes from master\n","stream":"stdout","time":"2020-02-19T04:06:09.6340791Z"}
{"log":"1:S 19 Feb 2020 04:06:09.860 * MASTER \u003c-\u003e REPLICA sync: Flushing old data\n","stream":"stdout","time":"2020-02-19T04:06:09.860296381Z"}
{"log":"1:S 19 Feb 2020 04:06:09.860 * MASTER \u003c-\u003e REPLICA sync: Loading DB in memory\n","stream":"stdout","time":"2020-02-19T04:06:09.860323416Z"}
{"log":"1:S 19 Feb 2020 04:06:09.860 # Wrong signature trying to load DB from file\n","stream":"stdout","time":"2020-02-19T04:06:09.860350539Z"}
{"log":"1:S 19 Feb 2020 04:06:09.860 # Failed trying to load the MASTER synchronization DB from disk\n","stream":"stdout","time":"2020-02-19T04:06:09.860370074Z"}
{"log":"1:S 19 Feb 2020 04:06:09.860 * Background append only file rewriting started by pid 2838\n","stream":"stdout","time":"2020-02-19T04:06:09.860887072Z"}
{"log":"1:S 19 Feb 2020 04:06:09.884 * AOF rewrite child asks to stop sending diffs.\n","stream":"stdout","time":"2020-02-19T04:06:09.884200771Z"}
{"log":"2838:C 19 Feb 2020 04:06:09.884 * Parent agreed to stop sending diffs. Finalizing AOF...\n","stream":"stdout","time":"2020-02-19T04:06:09.884224364Z"}
{"log":"2838:C 19 Feb 2020 04:06:09.884 * Concatenating 0.00 MB of AOF diff received from parent.\n","stream":"stdout","time":"2020-02-19T04:06:09.884232305Z"}
{"log":"2838:C 19 Feb 2020 04:06:09.884 * SYNC append only file rewrite performed\n","stream":"stdout","time":"2020-02-19T04:06:09.884301823Z"}
{"log":"2838:C 19 Feb 2020 04:06:09.884 * AOF rewrite: 2 MB of memory used by copy-on-write\n","stream":"stdout","time":"2020-02-19T04:06:09.885066707Z"}
{"log":"1:S 19 Feb 2020 04:06:09.908 * Background AOF rewrite terminated with success\n","stream":"stdout","time":"2020-02-19T04:06:09.908571705Z"}
{"log":"1:S 19 Feb 2020 04:06:09.908 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB)\n","stream":"stdout","time":"2020-02-19T04:06:09.908593368Z"}
{"log":"1:S 19 Feb 2020 04:06:09.908 * Background AOF rewrite finished successfully\n","stream":"stdout","time":"2020-02-19T04:06:09.908599805Z"}
{"log":"1:S 19 Feb 2020 04:06:10.510 * Connecting to MASTER *IP*:*PORT*\n","stream":"stdout","time":"2020-02-19T04:06:10.510484407Z"}
{"log":"1:S 19 Feb 2020 04:06:10.510 * MASTER \u003c-\u003e REPLICA sync started\n","stream":"stdout","time":"2020-02-19T04:06:10.510506838Z"}
{"log":"1:S 19 Feb 2020 04:06:10.742 * Non blocking connect for SYNC fired the event.\n","stream":"stdout","time":"2020-02-19T04:06:10.742327821Z"}
{"log":"1:S 19 Feb 2020 04:06:11.650 * Module 'system' loaded from /tmp/exp_lin.so\n","stream":"stdout","time":"2020-02-19T04:06:11.650188169Z"}
{"log":"1:M 19 Feb 2020 04:06:11.898 # Setting secondary replication ID to 1e9525bb8323b08b0d258e78ff5d33107da9c, valid up to offset: 1. New replication ID is e3274f106d6fd08e16306c574c12eacda2fca354\n","stream":"stdout","time":"2020-02-19T04:06:11.898549773Z"}
{"log":"1:M 19 Feb 2020 04:06:11.898 * MASTER MODE enabled (user request from 'id=1023 addr=*IP*:*PORT* fd=8 name= age=6 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=34 qbuf-free=32734 obl=0 oll=0 omem=0 events=r cmd=slaveof')\n","stream":"stdout","time":"2020-02-19T04:06:11.89859865Z"}
{"log":"sh: 1: killall: not found\n","stream":"stderr","time":"2020-02-19T04:06:12.722240613Z"}

文件中的配置Startup

public void ConfigureServices(IServiceCollection services)
{
    services.AddStackExchangeRedisCache(options =>
    {
        options.InstanceName = "SimpleCache";
        options.Configuration = "IP:PORT"
    });

    services.AddTransient<ICacheService, CacheService>();
    //services.AddSingleton<ICacheService, CacheService>(); ??
}

实施:

public class CacheService : ICacheService
{
    private readonly IDistributedCache _distributedCache;

    public CacheService(IDistributedCache distributedCache)
    {
        _distributedCache = distributedCache;
    }

    public async Task SetAsync(string key, byte[] value)
    {
        //is it ok to use this method without await keyword??
        await _distributedCache.SetAsync(key, value, token);
    }

    public async Task<byte[]> GetAsync(string key)
    {
        var value = await _distributedCache.GetAsync(key);
        return value;
    }
}

如果需要,我可以分享任何其他信息。

标签: linuxdockerasp.net-coreredisstackexchange.redis

解决方案


推荐阅读