美文网首页
redis.conf详解之timeout

redis.conf详解之timeout

作者: 小易哥学呀学 | 来源:发表于2021-11-21 21:49 被阅读0次

用法

单位是

timeout 3

用途

在timeout时间内如果没有数据交互,redis侧将关闭连接。
没有数据交互:redis客户端不向服务端发送任何数据。

注意事项

1.0代表永不断开(在macOS测试不受内核保活定时器影响)。
2.tcp/ip连接、unix socket连接均受timeout影响。
2.timeout 在源码中对应server.maxidletime
3.源码以及一些注释:

// 路径:timeout.c line:55

/* Check for timeouts. Returns non-zero if the client was terminated.
 * The function gets the current time in milliseconds as argument since
 * it gets called multiple times in a loop, so calling gettimeofday() for
 * each iteration would be costly without any actual gain. */
int clientsCronHandleTimeout(client *c, mstime_t now_ms) {
    time_t now = now_ms/1000;

    if (server.maxidletime &&
        /* This handles the idle clients connection timeout if set. */
        !(c->flags & CLIENT_SLAVE) &&   /* No timeout for slaves and monitors */
        !(c->flags & CLIENT_MASTER) &&  /* No timeout for masters */
        !(c->flags & CLIENT_BLOCKED) && /* No timeout for BLPOP */
        !(c->flags & CLIENT_PUBSUB) &&  /* No timeout for Pub/Sub clients */
        (now - c->lastinteraction > server.maxidletime)) // 当前时间-最后互动时间 大于 超时时间
    {
        serverLog(LL_VERBOSE,"Closing idle client");
        freeClient(c); // 释放连接
        return 1;
    } else if (c->flags & CLIENT_BLOCKED) {
        /* Cluster: handle unblock & redirect of clients blocked
         * into keys no longer served by this server. */
        if (server.cluster_enabled) {
            if (clusterRedirectBlockedClientIfNeeded(c))
                unblockClient(c);
        }
    }
    return 0;
}

macOS修改/查看保活时器参数

查看

sysctl -a | grep "net.inet.tcp.keep"

修改

sudo sysctl -w net.inet.tcp.keepidle=7200000
sudo sysctl -w net.inet.tcp.keepintvl=75000
sudo sysctl -w net.inet.tcp.keepinit=75000
sudo sysctl -w net.inet.tcp.keepcnt=8

linux查看保活定时器参数

cat /proc/sys/net/ipv4/tcp_keepalive_time
cat /proc/sys/net/ipv4/tcp_keepalive_intvl
cat /proc/sys/net/ipv4/tcp_keepalive_probes

原生注释

# Close the connection after a client is idle for N seconds (0 to disable)
#timeout 3

相关文章

  • redis.conf详解之timeout

    用法 单位是秒 用途 在timeout时间内如果没有数据交互,redis侧将关闭连接。没有数据交互:redis客户...

  • 2016-08-18 短信接口、ajax请求

    短信接口、ajax请求 ajax请求 $.ajax()方法详解 url type timeout: async: ...

  • redis.conf详解之include

    1、用法: 在 $yourPath/redis.conf 文件中添加以下配置 2、用途: 模块化配置,比如所有服务...

  • redis.conf详解之module

    1、用法: 在 $yourPath/redis.conf 文件中添加以下配置 2、module制作: 准备工作 1...

  • redis.conf详解之port

    用法 用途 指定redis监听的端口。 注意事项: 1.默认是63792.配置为0时将不监听任何端口(也就是服务没...

  • redis.conf详解之bind

    用法 绑定到本机的其中一个ip 绑定到本机的两个ip,如果10.0.0.1无效redis依旧可以启动。 绑定到本机...

  • redis.conf详解之daemonize

    用法 作为非守护进程运行 作为守护进程运行 注意事项: 默认情况下,Redis不作为守护进程运行。如果以守护进程运...

  • redis.conf详解之pidfile

    用法 注意事项: 如果pidfile文件创建失败,也不会影响redis启动。配置了daemonize或pidfil...

  • redis.conf详解之maxclients

    本文基于 redis_version:6.2.5 用法 设置一个redis实例支持的最大连接数。 注意事项: 默认...

  • Redis.conf 详解

    Redis.conf 详解 参考地址:https://www.cnblogs.com/zhang-ke/p/598...

网友评论

      本文标题:redis.conf详解之timeout

      本文链接:https://www.haomeiwen.com/subject/ilovtrtx.html