Migration Guide and Breaking Changes is not full enough
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.6k
- Forks
- 2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 40
Description
- 1) Many methods now is not available by old names (with
legacyModealso too)
So, only way for now (without modifying thousands of files) is patch client object like this, or remap keys with .toLowerCase():
client.hgetall = client.hGetAll;
client.hget = client.hGet;
client.hset = client.hSet;
client.hmset = client.hSet;
client.setex = client.setEx;
...
- 2)
hSetdoes not allow objects as second parameter anymore
client.hSet('key', {a: 1, b:2}, callback);
< ./node_modules/@node-redis/client/dist/lib/commander.js:72
yield `$${byteLength.toString()}${DELIMITER}`;
^
TypeError: Cannot read properties of undefined (reading 'toString')
at encodeCommand (./node_modules/@node-redis/client/dist/lib/commander.js:72:30)
at encodeCommand.next (<anonymous>)
at RedisSocket.writeCommand (./node_modules/@node-redis/client/dist/lib/client/socket.js:56:20)
at Commander._RedisClient_tick (./node_modules/@node-redis/client/dist/lib/client/index.js:415:64)
at Commander._RedisClient_sendCommand (./node_modules/@node-redis/client/dist/lib/client/index.js:396:82)
at Commander.sendCommand (./node_modules/@node-redis/client/dist/lib/client/index.js:349:93)
at Commander.<computed> (./node_modules/@node-redis/client/dist/lib/client/index.js:383:14)
But previously, on 3.x its works:
client.hmset('key', {a: 1, b: 2}, callback);
< HMSET key a 1 b 2
Functionality hiddenly broken, and no alternative provided.
Current solution is writing a wrap for hmset like this:
client.hmset = (hkey, parms, callback) => {
client.hSet(hkey, Object.entries(parms).flat(), callback)
}
- 3) Connection errors did not crash process with uncatched errors anymore. Strange thing, but seems like something changed in error policy of this module. I haven't figured it out yet, but when connection is lost, algorithm simply stop on redis
commandSendingforever.
- 4) (Bonus) Types for
legacyModeand callbacks is not provided, but in 3.x its does, and for 2.x too: https://www.npmjs.com/package/@types/redis,
Dirty way for now is patchnode_modules/@node-redis/client/dist/lib/client/index.d.tsand add it toWithCommandstype
export declare type RedisClientCommandSignatureLegacy<C extends RedisCommand> = (...args: [...options: Parameters<C['transformArguments']>, callback: (e: Error | null, result: RedisCommandReply<C>) => void]) => void
Also, I think that users can additionally import something like LegacyTypesHelper module that will override signatures until legacyMode enabled.
- 5) Importing of
{ RedisClient } from "redis"now is not available anymore.
Current solution is craft it by yourself: (but it seems like a crutch)
import { createClient } from 'redis'
type RedisClient = ReturnType<typeof createClient>
But I think develops can provide more useful type with generics, but not delete it at all.
Many things, like cache adapters, models or abstract classes require that type. Also, will be useful, if develop may declare that
code expected pure RedisClient or RedisClient with RediJson module.
Anyway it should be described in migration guide.
-
6) Another thing for the migration guide. SCAN args have changed, requiring
client.SCAN(cursor, { MATCH: keyPattern, COUNT: pageSize })pageSize is a Number. It used to takeclient.SCAN(cursorString, 'MATCH', keyPattern, 'COUNT', pageSize.toString()).And the response has changed. Instead of an array of strings
[<cursor>, <keys>],it now returns a structure{cursor: <number>, keys: <keys>}. (thx for reporting @jimsnab)
Finally, I should say that is very sad example of "how modules shouldn't make breaking updates", especially of so popular module. Feels like a spit into consumers.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the migration guide and the breaking-change points listed in this issue, then inspect the referenced client type declaration at node_modules/@node-redis/client/dist/lib/client/index.d.ts and the command behavior described for hSet and SCAN. Done means the guide documents the reported renamed methods, argument and response changes, connection-error behavior, legacy callback types, and RedisClient import migration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, redis, typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100