RicardoScofileld
V2EX  ›  Node.js

从 redis 中读取数据,写入文件会丢失数据吗?

  •  
  •   RicardoScofileld · Jul 13, 2018 · 4396 views
    This topic created in 2939 days ago, the information mentioned may be changed or developed.

    打算重构项目代码,发现数据量有点偏差,排查一通,想问问各位大佬,node 异步写入文件,会导致数据丢失吗?

    3 replies    2018-07-21 17:08:17 +08:00
    cqu1980
        1
    cqu1980  
       Jul 17, 2018
    有可能,在文件未写完的时候,直接反馈用户端,关闭连接,这个时候有可能丢,所以最好在异步完成后再给客户端返回信息。
    RicardoScofileld
        2
    RicardoScofileld  
    OP
       Jul 20, 2018   ❤️ 1
    @cqu1980 如果起两个进程,同时对一个文件进行写入操作会丢失数据吗?
    cqu1980
        3
    cqu1980  
       Jul 21, 2018
    要看是怎么写入,是追加还是创建一个文件并写入。追加不会,如果是创建文件并写入,可能会被覆盖。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2978 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 13:31 · PVG 21:31 · LAX 06:31 · JFK 09:31
    ♥ Do have faith in what you're doing.