Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions packages/client/lib/client/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,70 @@ describe('Client', () => {
minimumDockerVersion: [6, 2] // CLIENT INFO
});

testUtils.testWithClient('should remember selected db when a pipelined command fails', async client => {
// Regression: the SELECT ran on the server, but the INCR rejected the batch
// before the client recorded the database, so the reconnect went back to 0.
// The last of the three SELECTs is out of range, so the server ends on db 1.
const { databases } = await client.configGet('databases');
await assert.rejects(
client.multi()
.select(2)
.set('key', 'value')
.incr('key')
.select(1)
.select(Number(databases))
.execAsPipeline()
);

const duplicate = await client.duplicate().connect();
try {
await Promise.all([
once(client, 'error'),
duplicate.clientKill({
filter: 'ID',
id: await client.clientId()
})
]);
} finally {
duplicate.destroy();
}

assert.equal(
(await client.clientInfo()).db,
1
);
}, {
...GLOBAL.SERVERS.OPEN,
minimumDockerVersion: [6, 2] // CLIENT INFO
});

testUtils.testWithClient('should remember a db selected by a raw lowercase Buffer SELECT in a pipeline', async client => {
await client.multi()
.addCommand([Buffer.from('select'), '2'])
.execAsPipeline();

const duplicate = await client.duplicate().connect();
try {
await Promise.all([
once(client, 'error'),
duplicate.clientKill({
filter: 'ID',
id: await client.clientId()
})
]);
} finally {
duplicate.destroy();
}

assert.equal(
(await client.clientInfo()).db,
2
);
}, {
...GLOBAL.SERVERS.OPEN,
minimumDockerVersion: [6, 2] // CLIENT INFO
});

testUtils.testWithClient('should handle error replies (#2665)', async client => {
await assert.rejects(
client.multi()
Expand Down
9 changes: 5 additions & 4 deletions packages/client/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1886,17 +1886,18 @@ export default class RedisClient<
// rejections are collected by Promise.all, but the tracePromise wrapper
// is a separate branch that nobody awaits.
traced.catch(noop);
if (String(args[0]).toUpperCase() === 'SELECT') {
traced.then(() => {
this._self.#selectedDB = Number(args[1]);
}, noop);
}
Comment thread
cursor[bot] marked this conversation as resolved.
return traced;
})
);
this._self.#scheduleWrite();

const result = await promise;

if (selectedDB !== undefined) {
this._self.#selectedDB = selectedDB;
}

return result;
},
() => ({
Expand Down
Loading