简体   繁体   English

socket.io-redis尾部字节

[英]socket.io-redis trailing bytes

I am using socket.io-emitter to broadcast an event to a set of channels with a for loop: 我正在使用socket.io-emitter通过for循环将事件广播到一组通道:

In the file, I have: 在文件中,我有:

var io = require('socket.io-emitter')({
  host: 'localhost',
  port: 6379
});

module.exports = {
  exampleFunction: function(req, res, next) {
    var channels = req.param('channels'),
        data = req.param('data');

    for (var i=0; i<channels.length; i++) {
      io.to(channels[i]).emit('example event', data)
    }
  }
}

In app.js , I have socket.io-redis : app.js ,我有socket.io-redis

io.adapter(socketio_redis({ 
  host: 'localhost', 
  port: 6379,
  pubClient: redis.createClient(6379, '127.0.0.1'),
  subClient: redis.createClient(6379, '127.0.0.1')
}))

When I try to run exampleFunction , I get the following uncaught error in my console: 当我尝试运行exampleFunction ,在控制台中出现以下未捕获的错误:

Error: 348 trailing bytes
    at Object.decode (C:\Users\Website\socket.io-redis\node_modules\msgpack-js\msgpack.js:200:47)
    at Redis.onmessage (C:\Users\Website\socket.io-redis\index.js:93:24)
    at RedisClient.EventEmitter.emit (events.js:106:17)
    at RedisClient.return_reply (C:\Users\Website\node_modules\redis\index.js:672:22)
    at ReplyParser.<anonymous> (C:\Users\Website\node_modules\redis\index.js:309:14)
    at ReplyParser.EventEmitter.emit (events.js:95:17)
    at ReplyParser.send_reply (C:\Users\Website\node_modules\redis\lib\parser\javascript.js:300:10)
    at ReplyParser.execute (C:\Users\Website\node_modules\redis\lib\parser\javascript.js:211:22)
    at RedisClient.on_data (C:\Users\Website\node_modules\redis\index.js:534:27)
    at Socket.<anonymous> (C:\Website\node_modules\redis\index.js:91:14)

I have seen that this is from msgpack. 我已经知道这是来自msgpack。 Have any of you encountered this error before? 你们有没有遇到过这个错误? How did you resolve it? 您是如何解决的?

Thank you. 谢谢。

On the main page of nm.socket.io-redis it is written: nm.socket.io-redis的主页上写道:

Msgpack with giving us an error called "trailing bytes". Msgpack向我们提供了一个称为“跟踪字节”的错误。 After reading up we realized that we could just use JSON.stringfy/JSON.parse instead of msgpack. 阅读后,我们意识到我们可以只使用JSON.stringfy / JSON.parse而不是msgpack。

Which looks like the error you are getting. 看起来像您遇到的错误。 As it is suggested there, try JSON.strigfy 如建议的那样,尝试JSON.strigfy

Okay, We found the solution. 好的,我们找到了解决方案。 Refer to: https://github.com/Automattic/socket.io-redis/issues/17 请参阅: https : //github.com/Automattic/socket.io-redis/issues/17

As you can see, socket.io-emitter requires you set return_buffers to true on your redis client. 如您所见,socket.io-emitter要求您在redis客户端上将return_buffers设置为true。

Let me know if this works. 让我知道这个是否奏效。 Otherwise I can dif in the code some more. 否则,我可以在代码中添加更多内容。

This should answer your question. 这应该可以回答您的问题。 https://github.com/Automattic/socket.io-redis/issues/17 https://github.com/Automattic/socket.io-redis/issues/17

This helped me with Error: -560815898 trailing bytes error: 这帮助我解决以下Error: -560815898 trailing bytes错误:

  1. npm install msgpack-js-v5
  2. change file node_modules/socket.io-redis/index.js at the very top: 在最顶部更改文件node_modules/socket.io-redis/index.js

    var msgpack = require('msgpack-js');

    to

    var msgpack = require('msgpack-js-v5');

  3. now use code similar to this: 现在使用类似于以下的代码:

     var adapter = require('socket.io-redis'); var pub = redis.createClient(6379, 'localhost'); var sub = redis.createClient(6379, 'localhost', { return_buffers: true }); io.adapter(adapter({pubClient: pub, subClient: sub})); 

UPDATE: 更新:

In some days I stumbled upon an error bops.readUInt64BE is not a function , so eventually I switched msgpack-js-v5 to msgpack5 and now it works ok. bops.readUInt64BE is not a function我偶然发现了一个错误bops.readUInt64BE is not a function ,所以最终我将msgpack-js-v5切换为msgpack5 ,现在可以正常使用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM