You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
chore(examples): fix examples for v5 (#2938)
This commit is contained in:
committed by
GitHub
parent
bd5c230c62
commit
2c9ad2e772
@@ -1,6 +1,6 @@
|
||||
// How to mix and match supported commands that have named functions with
|
||||
// How to mix and match supported commands that have named functions with
|
||||
// commands sent as arbitrary strings in the same transaction context.
|
||||
// Use this when working with new Redis commands that haven't been added to
|
||||
// Use this when working with new Redis commands that haven't been added to
|
||||
// node-redis yet, or when working with commands that have been added to Redis
|
||||
// by modules other than those directly supported by node-redis.
|
||||
|
||||
@@ -23,18 +23,29 @@ await client.sendCommand(['hset', 'hash2', 'number', '3']);
|
||||
// In a transaction context, use addCommand to send arbitrary commands.
|
||||
// addCommand can be mixed and matched with named command functions as
|
||||
// shown.
|
||||
const responses = await client
|
||||
.multi()
|
||||
const multi = client.multi()
|
||||
.hGetAll('hash2')
|
||||
.addCommand(['hset', 'hash3', 'number', '4'])
|
||||
.hGet('hash3', 'number')
|
||||
.exec();
|
||||
.hGet('hash3', 'number');
|
||||
|
||||
// exec() returns Array<ReplyUnion>
|
||||
const responses = await multi.exec();
|
||||
|
||||
// responses will be:
|
||||
// [ [Object: null prototype] { name: 'hash2', number: '3' }, 0, '4' ]
|
||||
console.log(responses);
|
||||
console.log('Using exec():', responses);
|
||||
|
||||
// This is equivalent to multi.exec<'typed'>()
|
||||
const typedResponses = await multi
|
||||
.hGetAll('hash2')
|
||||
.addCommand(['hset', 'hash3', 'number', '4'])
|
||||
.hGet('hash3', 'number')
|
||||
.execTyped();
|
||||
|
||||
// typedResponses will have more specific types
|
||||
console.log('Using execTyped():', typedResponses);
|
||||
|
||||
// Clean up fixtures.
|
||||
await client.del(['hash1', 'hash2', 'hash3']);
|
||||
|
||||
client.destroy();
|
||||
client.close();
|
||||
|
Reference in New Issue
Block a user