[real-time] backwards compatibility fix for redis 6.2 (#24734)

GitOrigin-RevId: ffc51a8280e0d0708e7dcb2638cabed2b7adfbf5
This commit is contained in:
Jakob Ackermann
2025-04-08 18:12:33 +01:00
committed by Copybot
parent ca111771c2
commit 3f10b29869
2 changed files with 20 additions and 20 deletions
@@ -158,24 +158,26 @@ module.exports = {
} else {
// Only populate projectNotEmptySince when more clients remain connected.
const nowInSeconds = Math.ceil(Date.now() / 1000).toString()
rclient.set(
// We can go back to SET GET after upgrading to redis 7.0+
const multi = rclient.multi()
multi.get(Keys.projectNotEmptySince({ projectId }))
multi.set(
Keys.projectNotEmptySince({ projectId }),
nowInSeconds,
'NX',
'GET',
'EX',
31 * ONE_DAY_IN_S,
(err, res) => {
if (err) {
logger.warn(
{ err, projectId },
'could not set/collect projectNotEmptySince'
)
} else if (res) {
recordProjectNotEmptySinceMetric(res, status)
}
}
31 * ONE_DAY_IN_S
)
multi.exec((err, res) => {
if (err) {
logger.warn(
{ err, projectId },
'could not get/set projectNotEmptySince'
)
} else if (res[0]) {
recordProjectNotEmptySinceMetric(res[0], status)
}
})
}
callback(err)
})
@@ -448,7 +448,7 @@ describe('ConnectedUsersManager', function () {
)
})
it('should clear the projectNotEmptySince key when empty and record metric if set', function (done) {
this.rClient.exec.yields(null, [1, 0])
this.rClient.exec.onFirstCall().yields(null, [1, 0])
tk.freeze(1_234_000)
this.rClient.getdel.yields(null, '1230')
this.ConnectedUsersManager.markUserAsDisconnected(
@@ -470,9 +470,9 @@ describe('ConnectedUsersManager', function () {
)
})
it('should set projectNotEmptySince key when single and skip metric if not set before', function (done) {
this.rClient.exec.yields(null, [1, 1])
this.rClient.exec.onFirstCall().yields(null, [1, 1])
tk.freeze(1_233_001) // should ceil up
this.rClient.set.yields(null, '')
this.rClient.exec.onSecondCall().yields(null, [''])
this.ConnectedUsersManager.markUserAsDisconnected(
this.project_id,
this.client_id,
@@ -482,7 +482,6 @@ describe('ConnectedUsersManager', function () {
`projectNotEmptySince:{${this.project_id}}`,
'1234',
'NX',
'GET',
'EX',
31 * 24 * 60 * 60
)
@@ -511,9 +510,9 @@ describe('ConnectedUsersManager', function () {
cases
)) {
it(name, function (done) {
this.rClient.exec.yields(null, [1, nConnectedClients])
this.rClient.exec.onFirstCall().yields(null, [1, nConnectedClients])
tk.freeze(1_235_000)
this.rClient.set.yields(null, '1230')
this.rClient.exec.onSecondCall().yields(null, ['1230'])
this.ConnectedUsersManager.markUserAsDisconnected(
this.project_id,
this.client_id,
@@ -523,7 +522,6 @@ describe('ConnectedUsersManager', function () {
`projectNotEmptySince:{${this.project_id}}`,
'1235',
'NX',
'GET',
'EX',
31 * 24 * 60 * 60
)