* wip * Worked on phrasing etc for v5 doc changes. * Removed quite repetition of 'Rather' * Update v4-to-v5.md * Update v4-to-v5.md * Update v4-to-v5.md * WIP * WIP * clean SET command * some more commands, multi.exec<'typed'> * "typed" multi * WIP * upgrade deps * wip * wip * fix #2469 * wip * npm update * wip * wip * wip * wip * some tests * tests.yml * wip * wip * merge master into v5 * some more commands * some more commands * WIP * Release client@2.0.0-next.1 --------- Co-authored-by: Simon Prickett <simon@redislabs.com>
3.5 KiB
v4 to v5 migration guide
Command Options
In v4, command options are passed as a first optional argument:
await client.get('key'); // `string | null`
await client.get(client.commandOptions({ returnBuffers: true }), 'key'); // `Buffer | null`
This has a couple of flaws:
- The argument types are checked in runtime, which is a performance hit.
- Code suggestions are less readable/usable, due to "function overloading".
- Overall, "user code" is not as readable as it could be.
The new API for v5
With the new API, instead of passing the options directly to the commands we use a "proxy client" to store them:
await client.get('key'); // `string | null`
const proxyClient = client.withCommandOptions({
flags: {
[TYPES.BLOB_STRING]: Buffer
}
});
await proxyClient.get('key'); // `Buffer | null`
withCommandOptions
can be used to override all of the command options, without reusing any existing ones.
To override just a specific option, use the following functions:
withFlags
- overrideflags
only.asap
- overrideasap
totrue
.isolated
- overrideisolated
totrue
.
Quit VS Disconnect
The QUIT
command has been deprecated in Redis 7.2 and should now also be considered deprecated in Node-Redis. Instead of sending a QUIT
command to the server, the client can simply close the network connection.
Rather than using client.quit()
, your code should use client.close()
or client.disconnect()
.
TODO difference between close
and disconnect
...
Scan Iterators
TODO
Yields chunks instead of individual items:
for await (const chunk of client.scanIterator()) {
// `chunk` type is `Array<string>`
// will allow multi keys operations
await client.del(chunk);
}
Commands
Some command arguments/replies have changed to align more closely to data types returned by Redis:
ACL GETUSER
:selectors
CLIENT KILL
:enum ClientKillFilters
->const CLIENT_KILL_FILTERS
1CLUSTER FAILOVER
:enum FailoverModes
->const FAILOVER_MODES
1LCS IDX
:length
has been changed tolen
,matches
has been changed fromArray<{ key1: RangeReply; key2: RangeReply; }>
toArray<[key1: RangeReply, key2: RangeReply]>
HEXISTS
:boolean
->number
2HRANDFIELD_COUNT_WITHVALUES
:Record<BlobString, BlobString>
->Array<{ field: BlobString; value: BlobString; }>
(it can return duplicates).SCAN
,HSCAN
,SSCAN
, andZSCAN
: cursor type isstring
instead ofnumber
?HSETNX
:boolean
->number
2ZINTER
: instead ofclient.ZINTER('11, { WEIGHTS: [1] })
useclient.ZINTER({ key: '1', weight: 1 }])
SETNX
:boolean
->number
2COPY
:destinationDb
->DB
,replace
->REPLACE
,boolean
->number
2EXPIRE
:boolean
->number
2EXPIREAT
:boolean
->number
2MOVE
:boolean
->number
2PEXPIRE
:boolean
->number
2PEXPIREAT
:boolean
->number
2RENAMENX
:boolean
->number
2HSCAN
:tuples
has been renamed toentries
PFADD
:boolean
->number
2SCRIPT EXISTS
:Array<boolean>
->Array<number>
2SISMEMBER
:boolean
->number
2SMISMEMBER
:Array<boolean>
->Array<number>
2