1
0
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:
Nikolay Karadzhov
2025-05-05 11:35:41 +03:00
committed by GitHub
parent bd5c230c62
commit 2c9ad2e772
20 changed files with 133 additions and 75 deletions

View File

@@ -6,7 +6,13 @@ const client = createClient();
await client.connect();
const serverTime = await client.time();
// 2022-02-25T12:57:40.000Z { microseconds: 351346 }
// In v5, TIME returns [unixTimestamp: string, microseconds: string] instead of Date
// Example: ['1708956789', '123456']
console.log(serverTime);
client.destroy();
// Convert to JavaScript Date if needed
const [seconds, microseconds] = serverTime;
const date = new Date(parseInt(seconds) * 1000 + parseInt(microseconds) / 1000);
console.log('Converted to Date:', date);
client.close();