首页 \ 问答 \ 如何杀死Redis上由Node打开的闲置客户端?(How to kill idle clients opened by Node on Redis?)

如何杀死Redis上由Node打开的闲置客户端?(How to kill idle clients opened by Node on Redis?)

我很难自动关闭Redis的客户端连接。 这当然是redis包的一个问题:

https://www.npmjs.com/package/redis

Redis将保持连接一直保持活动状态,直到您关闭它们或达到默认为无限的超时值。

我知道这一点:

我如何杀死闲置的redis客户端

甚至在阅读之前,我试图通过.conf文件和命令行设置timeout配置,但它们都没有工作。

实际发生的事情非常奇怪:

如果我在N秒后运行CLIENT LIST

  • 仍有相同数量的空闲连接
  • 客户端的'空闲'信息从0重新开始(例如,如果我设置了10秒的超时时间,11秒后idle信息为1)。
  • 地址变化。 端口号会随着创建新连接而更改,以免丢失该客户端。
  • 客户端实际上连接到节点。 这似乎是一个新的节点过程。 如果我保持节点应用程序UP连接不会死。 如果我关闭应用程序所有由它创建的连接关闭。 所以redis模块可能是'重新启动'连接。

关于我应该怎样强制“杀死”被杀害客户的任何想法?

Obs:我知道我可以用'quit()'来关闭客户端的连接,但是我必须保证在一段时间后它将摆脱任何未被应用程序关闭的闲置客户端。


I'm having a very difficult time to automatically close Redis' client connections. It is most certainly a problem with the redis package:

(https://www.npmjs.com/package/redis)

Redis will keep connections alive until you close them or a timeout, that defaults to infinite, is reached.

I'm aware of this:

how do I kill idle redis clients

And even before reading on SO I tried to set the timeout config both by .conf file and by command line but none of them worked.

What actually happens is very weird:

If I run CLIENT LIST after the N seconds:

  • The same number of idle connections are still there
  • The client 'idle' info restarts from 0 (for example, if I set 10 seconds of timeout, after 11 seconds the idle info is 1).
  • The addr changes. The port number changes as it is creating new connections to not lose that client.
  • The client is actually attached to Node. It seems to be a new node process. If I keep the node app UP the connections won't die. If I close the app all connections created by it close. So redis module is probably 'restarting' the connection.

Any ideas on what I should do not force the 'resurection' of a killed client?

Obs: I understand I can close the client's connection with 'quit()', but I must assure it will get rid of any idle client that wasn't closed by the application after some time.


原文:https://stackoverflow.com/questions/42721785
更新时间:2021-12-29 20:12

最满意答案

这是使用投影的Spring代码。 您可能需要根据从Spring上下文获取MongoOperations对象的方式替换此代码“getMongoConnection()”。

使用投影的聚合方法: -

public Boolean aggregateMyTypeCollectionUsingProject() {

        MongoOperations mongoOperations = getMongoConnection();

        ProjectionOperation  project = Aggregation.project().and("props.city").as("city").and("props.age").as("person.age").andExpression("name")
                .as("person.name");
        Aggregation aggregate = Aggregation.newAggregation(project);

        System.out.println(aggregate.toString());
        AggregationResults<DBObject> results = mongoOperations.aggregate(aggregate, MyType.class, DBObject.class);

        System.out.println("Result ============>" + results.getMappedResults());
        return true;

    }

我的getMongoConnection()方法: -

@SuppressWarnings("resource")
public MongoOperations getMongoConnection() {

    return (MongoOperations) new AnnotationConfigApplicationContext(SpringMongoConfig.class)
            .getBean("mongoTemplate");
}

查询: -

{ "aggregate" : "__collection__" , "pipeline" : [ { "$project" : { "city" : "$props.city" , "person.age" : "$props.age" , "person.name" : "$name"}}]}

输出: -

{
    "_id": {
        "$oid": "57b32d31ced49443e4b79f0d"
    },
    "city": "Moscow",
    "person": {
        "age": "26",
        "name": "Dmitry"
    }
}

Here is the Spring code using projection. You may need to replace this code "getMongoConnection()" based on how you get MongoOperations object from Spring context.

Aggregate method using projection:-

public Boolean aggregateMyTypeCollectionUsingProject() {

        MongoOperations mongoOperations = getMongoConnection();

        ProjectionOperation  project = Aggregation.project().and("props.city").as("city").and("props.age").as("person.age").andExpression("name")
                .as("person.name");
        Aggregation aggregate = Aggregation.newAggregation(project);

        System.out.println(aggregate.toString());
        AggregationResults<DBObject> results = mongoOperations.aggregate(aggregate, MyType.class, DBObject.class);

        System.out.println("Result ============>" + results.getMappedResults());
        return true;

    }

My getMongoConnection() method:-

@SuppressWarnings("resource")
public MongoOperations getMongoConnection() {

    return (MongoOperations) new AnnotationConfigApplicationContext(SpringMongoConfig.class)
            .getBean("mongoTemplate");
}

Query:-

{ "aggregate" : "__collection__" , "pipeline" : [ { "$project" : { "city" : "$props.city" , "person.age" : "$props.age" , "person.name" : "$name"}}]}

Output:-

{
    "_id": {
        "$oid": "57b32d31ced49443e4b79f0d"
    },
    "city": "Moscow",
    "person": {
        "age": "26",
        "name": "Dmitry"
    }
}

相关问答

更多
  • 工作查询应如下所示: Child childAlias = null; Parent parentAlias = null; int[] parentIds = new int[] {1, 2, 3}; var temp = sess.QueryOver() .JoinQueryOver(p => p.Children, () => childAlias) .WhereRestrictionOn(c => c.Parent.ID).IsIn(parentIds) . ...
  • 如果您已经有单独的FieldEditors的onChange处理程序,我不明白为什么不能将状态移动到FormEditor组件,只需将一个回调从那里传递到将更新父状态的FieldEditors。 对我来说,这似乎是一个更有反应的方式。 这可能是一些事情: var FieldEditor = React.createClass({ handleChange: function(event) { var text = event.target.value; this.props.onChan ...
  • 在你的情况下, $first_child不是一个jQuery集合。 你需要用$()包装它。 这是一个更正版本。 var first_child = $(xmlData).children()[0]; // [0] actually returns the first "raw" node var first_name = first_child.nodeName; var $first_child = $(first_child); var ...
  • 你所描述的是map方法: Integer valA = foo.getFoob().map(f -> f.getValA()).orElse(null); 如果该值存在,则map让您可以将函数内的值转换为函数,并且只有当值不存在时才更改可选类型。 还要注意,你可以从映射函数中返回null,在这种情况下结果将是Optional.empty() 。 What you are describing is the map method: Integer valA = foo.getFoob().map(f -> ...
  • 也许我对OpenERP的识字能力不足以使这种关联正确发生,或者没有足够的相关文档,或者ORM不是为此用途(或这些的任何组合)设计的,但我需要按照我的要求工作现在确实如此。 如果它以任何方式令人反感,我道歉。 批评和建议总是受欢迎。 def create(self, cr, uid, vals, context=None): """Creates a new dbe.document instance. Called by both internal app and client. do ...
  • 用CSS代替它。 没有必要为此使用jQuery。 .hiddenchild { display: none; } .dynamicallygenerated:last-child .hiddenchild { display: block; }
    a bunch of content
    1
  • 这是使用投影的Spring代码。 您可能需要根据从Spring上下文获取MongoOperations对象的方式替换此代码“getMongoConnection()”。 使用投影的聚合方法: - public Boolean aggregateMyTypeCollectionUsingProject() { MongoOperations mongoOperations = getMongoConnection(); ProjectionOperation projec ...
  • 这是自然语言处理 (NLP),更具体地说是问答和对话系统/ 聊天机器人的组合 。 如果你谷歌这些术语+“开源”,你会发现很多东西,但不要指望任何东西可以开箱即用。 最好先拿一本关于这个主题的书; 经典是Jurafsky&Martin 。 That's natural language processing (NLP), more specifically a combination of question answering and dialogue systems/chatterbots. If you ...
  • 您可以访问炮塔儿童。 问题是您需要将炮塔MovieClip内的坐标转换为PageOne MovieClip内的坐标: var b: Bullet = new Bullet(); var turretpoint:Point = new Point(player.turret.width, 0); var pagepoint: Point = this.globalToLocal(player.turret.localToGlobal(turretpoint)); b.rotation = (player. ...
  • 从技术上讲,它们是doctype的属性,而不是Fields。 所以我相信这就是你要找的东西: @ page.GetProperty( “pageContent”)。价值 截断...... @ Library.Truncate(@ page.GetProperty( “pageContent”)。值,100) 但是在这种情况下你应该能够简单地使用...... @ page.pageContent 所以... @ Library.Truncate(@ page.pageContent,100) …应该管用! T ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。