Skip to content

Commit

Permalink
fix message cache
Browse files Browse the repository at this point in the history
  • Loading branch information
sachaw committed Feb 19, 2024
1 parent 7a1e466 commit 956b839
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true,
"[prisma]": {
"editor.defaultFormatter": "Prisma.prisma-insider"
"editor.defaultFormatter": "Prisma.prisma"
}
}
12 changes: 10 additions & 2 deletions src/lib/mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class MqttQueue {
this.lastWorked = new Date();
}

private textDecoder = new TextDecoder();

public push(packet: Protobuf.Mqtt.ServiceEnvelope) {

Check warning on line 58 in src/lib/mqtt.ts

View workflow job for this annotation

GitHub Actions / quality

Excessive complexity detected.
if (packet.packet?.payloadVariant.case === "decoded") {
const data = packet.packet?.payloadVariant.value;
Expand All @@ -69,8 +71,14 @@ class MqttQueue {
} else if (data.portnum === Protobuf.Portnums.PortNum.TEXT_MESSAGE_APP) {
//cache in redis
redis.set(
`mqttMessage-${packet.gatewayId}-${packet.channelId}-${packet.packet.id}`,
data.toJsonString(),
`mqttMessage-${packet.gatewayId}-${
packet.channelId
}-${new Date().getTime()}`,
JSON.stringify({
from: packet.packet.from,
to: packet.packet.to,
message: this.textDecoder.decode(data.payload),
}),
{
EX: 60 * 60 * 12, // 12 hours

Check warning on line 83 in src/lib/mqtt.ts

View workflow job for this annotation

GitHub Actions / quality

This object property name should be in camelCase.
},
Expand Down

0 comments on commit 956b839

Please sign in to comment.