1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

V5 bringing RESP3, Sentinel and TypeMapping to node-redis

RESP3 Support
   - Some commands responses in RESP3 aren't stable yet and therefore return an "untyped" ReplyUnion.
 
Sentinel

TypeMapping

Correctly types Multi commands

Note: some API changes to be further documented in v4-to-v5.md
This commit is contained in:
Shaya Potter
2024-10-15 17:46:52 +03:00
committed by GitHub
parent 2fc79bdfb3
commit b2d35c5286
1174 changed files with 45931 additions and 36274 deletions

View File

@@ -91,5 +91,5 @@ await client.connect();
// Add your example code here...
await client.quit();
client.destroy();
```

View File

@@ -27,4 +27,4 @@ console.log('blpopPromise resolved');
// {"key":"keyName","element":"value"}
console.log(`listItem is '${JSON.stringify(listItem)}'`);
await client.quit();
client.destroy();

View File

@@ -77,4 +77,4 @@ const info = await client.bf.info('mybloom');
// }
console.log(info);
await client.quit();
client.destroy();

View File

@@ -25,4 +25,4 @@ console.log('Afer connectPromise has resolved...');
// isReady will return True here, client is ready to use.
console.log(`client.isOpen: ${client.isOpen}, client.isReady: ${client.isReady}`);
await client.quit();
client.destroy();

View File

@@ -1,25 +1,31 @@
// Define a custom script that shows example of SET command
// with several modifiers.
import { createClient } from 'redis';
import { createClient } from '../packages/client';
const client = createClient();
await client.connect();
await client.del('mykey');
let result = await client.set('mykey', 'myvalue', {
EX: 60,
GET: true
});
console.log(
await client.set('mykey', 'myvalue', {
expiration: {
type: 'EX',
value: 60
},
GET: true
})
); // null
console.log(result); //null
console.log(
await client.set('mykey', 'newvalue', {
expiration: {
type: 'EX',
value: 60
},
GET: true
})
); // 'myvalue'
result = await client.set('mykey', 'newvalue', {
EX: 60,
GET: true
});
console.log(result); //myvalue
await client.quit();
await client.close();

View File

@@ -23,4 +23,4 @@ try {
console.log(`GET command failed: ${e.message}`);
}
await client.quit();
client.destroy();

View File

@@ -77,4 +77,4 @@ console.log('Count-Min Sketch info:');
// }
console.log(info);
await client.quit();
client.destroy();

View File

@@ -76,4 +76,4 @@ const info = await client.cf.info('mycuckoo');
// }
console.log(info);
await client.quit();
client.destroy();

View File

@@ -1,22 +1,26 @@
// This example demonstrates the use of the DUMP and RESTORE commands
import { commandOptions, createClient } from 'redis';
import { createClient, RESP_TYPES } from 'redis';
const client = createClient();
await client.connect();
const client = await createClient({
commandOptions: {
typeMapping: {
[RESP_TYPES.BLOB_STRING]: Buffer
}
}
}).on('error', err => {
console.log('Redis Client Error', err);
}).connect();
// DUMP a specific key into a local variable
const dump = await client.dump(
commandOptions({ returnBuffers: true }),
'source'
);
const dump = await client.dump('source');
// RESTORE into a new key
await client.restore('destination', 0, dump);
// RESTORE and REPLACE an existing key
await client.restore('destination', 0, dump, {
REPLACE: true
REPLACE: true
});
await client.quit();
await client.close();

View File

@@ -9,4 +9,4 @@ const serverTime = await client.time();
// 2022-02-25T12:57:40.000Z { microseconds: 351346 }
console.log(serverTime);
await client.quit();
client.destroy();

View File

@@ -48,4 +48,4 @@ try {
console.error(e);
}
await client.quit();
client.destroy();

View File

@@ -24,4 +24,4 @@ await client.connect();
await client.set('mykey', '5');
console.log(await client.mincr('mykey', 'myotherkey', 10)); // [ 15, 10 ]
await client.quit();
client.destroy();

View File

@@ -73,4 +73,4 @@ const numPets = await client.json.arrLen('noderedis:jsondata', '$.pets');
// We now have 4 pets.
console.log(`We now have ${numPets} pets.`);
await client.quit();
client.destroy();

View File

@@ -6,7 +6,7 @@
"private": true,
"type": "module",
"dependencies": {
"redis": "../"
"redis": "../packages/client"
}
}

View File

@@ -85,4 +85,4 @@ for (const doc of results.documents) {
console.log(`${doc.id}: ${doc.value.name}, ${doc.value.age} years old.`);
}
await client.quit();
client.destroy();

View File

@@ -145,4 +145,4 @@ console.log(
// ]
// }
await client.quit();
client.destroy();

View File

@@ -88,4 +88,4 @@ console.log(JSON.stringify(results, null, 2));
// }
// ]
// }
await client.quit();
client.destroy();

View File

@@ -12,4 +12,4 @@ for await (const member of client.sScanIterator(setName)) {
console.log(member);
}
await client.quit();
client.destroy();

View File

@@ -28,4 +28,4 @@ for await (const memberWithScore of client.zScanIterator('mysortedset')) {
console.log(memberWithScore);
}
await client.quit();
client.destroy();

View File

@@ -47,4 +47,4 @@ console.log(`Length of mystream: ${await client.xLen('mystream')}.`);
// Should be approximately 1000:
console.log(`Length of mytrimmedstream: ${await client.xLen('mytrimmedstream')}.`);
await client.quit();
client.destroy();

View File

@@ -119,4 +119,4 @@ try {
console.error(e);
}
await client.quit();
client.destroy();

View File

@@ -110,4 +110,4 @@ const [ simonCount, lanceCount ] = await client.topK.count('mytopk', [
console.log(`Count estimate for simon: ${simonCount}.`);
console.log(`Count estimate for lance: ${lanceCount}.`);
await client.quit();
client.destroy();

View File

@@ -37,4 +37,4 @@ console.log(responses);
// Clean up fixtures.
await client.del(['hash1', 'hash2', 'hash3']);
await client.quit();
client.destroy();