Open npdev453 opened 2 years ago
I agree with you, and I have encountered the same first problem as you these days right after my pr.
To be honest, I think that as a package with millions of downloads every week, if developers want to release a new major version, they should complete the change log and migration guide before proceeding. Because this will cause a big impact, but only developers can quickly find all changes, it is difficult for us as users to find all changes.
I maintain the connect-redis
package. v4 is breaking enough that it is no longer interoperable with packages like ioredis
and redis-mock
(which are also both supported). I thought using legacyMode
would allow a period for connect-redis users to migrate and support both Redis v3 or v4 as well the other redis clients but it doesn't really work as this case points out, there are methods missing (.e.g. mget
) and signatures are incomplete. At this point I think we have to support and recommend v3 until we have something more interoperable. Are there plans to flesh out legacyMode
further?
Also doesn't mention:
import { RedisClient }
Also doesn't mention:
- What happened to
import { RedisClient }
Thanks, forgot about it. Already added to the list
The migration guide should explain how to modify RedisClient for purposes of unit test mocks.
(Was it really necessary to prevent a RedisClient object from being modified or extended?)
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 take client.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>}
.
The migration guide should explain how to modify RedisClient for purposes of unit test mocks.
(Was it really necessary to prevent a RedisClient object from being modified or extended?)
Could you please explain in details? You are free to modify client
object after calling const client = createClient();
My unit tests had class MockRedisClient extends redis.RedisClient {
.
This has to be completely reworked.
Anyone know where can I find the old V3 docs? While the changelog and migration guide are very helpful at telling me how things work in the new version compared to the previous one, I'm having trouble finding the documentation on what hasn't changed. There are a lot of gaps to fill if you aren't someone who is migrating to V4 but instead are starting off with V4.
Also the docs here need to be updated or - probably better - clearly identified as relevant to V3 - I've only been tinkering the repo for a couple hours so far, and almost every example there that I had to use is now out of date. 😄
@jayeclark the old docs can be found in the v3.1 branch. I'll make sure that https://docs.redis.com/latest/rs/references/client_references/client_nodejs/ will be updated. If you can prepare a list of what is missing in the docs it'll be very helpful.
@leibale oh, that makes perfect sense - I can’t believe I didn’t think to look there. 🤦 Sure, I can make a list as I go through - may not be comprehensive but it should be a good start especially for newer users.
Using this workaround for expressing the client type:
type RedisClient = ReturnType<typeof createClient>;
does not seem to give a very good type. It's sort of like it treats nonexistent commands as any
. Here's a Typescript playground to demonstrate the issue.
Using this workaround for expressing the client type:
type RedisClient = ReturnType<typeof createClient>;
does not seem to give a very good type. It's sort of like it treats nonexistent commands as
any
. Here's a Typescript playground to demonstrate the issue.
I was having trouble finding the type of the client and this helped me solve my problem, but it shouldn't be the way to go, rather there should be a clean type client that can be imported and used.
legacyMode
also too)So, only way for now (without modifying thousands of files) is patch client object like this, or remap keys with
.toLowerCase()
:hSet
does not allow objects as second parameter anymoreBut previously, on 3.x its works:
Functionality hiddenly broken, and no alternative provided.
Current solution is writing a wrap for
hmset
like this:commandSending
forever.legacyMode
and 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 patch
node_modules/@node-redis/client/dist/lib/client/index.d.ts
and add it toWithCommands
typeAlso, 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)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.