You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having regrets after migrating from ioredis because of the lack of prefix option which is causing a ton of issues using Redis in CI.
The problem is that (in the CI) it is desirable to isolate tests, which we do in PostgreSQL by creating a dedicated database, and in Redis, we used to do it with a prefix.
In the absence of Redis prefix, we've resolved to using workarounds like the one that I documented in #1657:
/** * https://github.com/redis/node-redis/issues/1657#issuecomment-2873493460 */constcreateRedisDatabaseAssigner=async({ url }: {url: string})=>{constredisMain=(awaitcreateClient({// We use database 0 as a main database for test run id storage.database: 0,
url,}).connect())asRedisClientType;return{assignDatabase: async({ testRunId }: {testRunId: string})=>{letassignedDatabase=(awaitredisMain.get(`assigned-database:${testRunId}`,))
? Number(awaitredisMain.get(`assigned-database:${testRunId}`))
: null;letnewAssignedDatabase=false;if(!assignedDatabase){constlastDatabase=(awaitredisMain.get('last-database'))
? Number(awaitredisMain.get('last-database'))
: 0;// By default there are 16 databases (indexed from 0 to 15) and// you can navigate between them using select command.// Beware that this means that this concurrency control will break// if we run more than 16 tests concurrently.assignedDatabase=lastDatabase>14 ? 1 : lastDatabase+1;awaitredisMain.set('last-database',assignedDatabase);awaitredisMain.set(`assigned-database:${testRunId}`,assignedDatabase);newAssignedDatabase=true;}constredis=(awaitcreateClient({database: assignedDatabase,
url,}).connect())asRedisClientType;if(newAssignedDatabase){awaitredis.flushDb();}returnredis;},};};
However, this means that our test runners are limited to running at most 15 tests in parallel, which is far from ideal.
Meanwhile, having the ability to configure a prefix provides a very elegant way to isolate these environments.
Additionally, prefixes are necessary to clearly separate concerns of different parts of the application, e.g. web app from various background workers, etc. and the absence of prefix makes it extremely cumbersome and dependent on whatever libraries that we use.
Uh oh!
There was an error while loading. Please reload this page.
Motivation
Having regrets after migrating from ioredis because of the lack of prefix option which is causing a ton of issues using Redis in CI.
The problem is that (in the CI) it is desirable to isolate tests, which we do in PostgreSQL by creating a dedicated database, and in Redis, we used to do it with a prefix.
In the absence of Redis prefix, we've resolved to using workarounds like the one that I documented in #1657:
However, this means that our test runners are limited to running at most 15 tests in parallel, which is far from ideal.
Meanwhile, having the ability to configure a prefix provides a very elegant way to isolate these environments.
Additionally, prefixes are necessary to clearly separate concerns of different parts of the application, e.g. web app from various background workers, etc. and the absence of prefix makes it extremely cumbersome and dependent on whatever libraries that we use.
Related issues:
The text was updated successfully, but these errors were encountered: