1
0
mirror of https://github.com/redis/node-redis.git synced 2025-07-31 05:44:24 +03:00
Files
node-redis/examples/get-server-time.js
2025-05-05 11:35:41 +03:00

19 lines
546 B
JavaScript

// Get the time from the Redis Server.
import { createClient } from 'redis';
const client = createClient();
await client.connect();
const serverTime = await client.time();
// In v5, TIME returns [unixTimestamp: string, microseconds: string] instead of Date
// Example: ['1708956789', '123456']
console.log(serverTime);
// 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();