Skip to content

Commit bb6be26

Browse files
Merge ad5ed41 into 9180b91
2 parents 9180b91 + ad5ed41 commit bb6be26

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This folder contains example scripts showing how to use Node Redis in different
1010
| `connect-as-acl-user.js` | Connect to Redis 6 using an ACL user |
1111
| `count-min-sketch.js` | Estimate the frequency of a given event using the [RedisBloom](https://redisbloom.io) Count-Min Sketch |
1212
| `cuckoo-filter.js` | Space efficient set membership checks with a [Cuckoo Filter](https://en.wikipedia.org/wiki/Cuckoo_filter) using [RedisBloom](https://redisbloom.io) |
13+
| `get-server-time.js` | Get the time from the Redis server |
1314
| `lua-multi-incr.js` | Define a custom lua script that allows you to perform INCRBY on multiple keys |
1415
| `managing-json.js` | Store, retrieve and manipulate JSON data atomically with [RedisJSON](https://redisjson.io/) |
1516
| `search-hashes.js` | Uses [RediSearch](https://redisearch.io) to index and search data in hashes |

examples/get-server-time.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Get the time from the Redis Server.
2+
3+
import { createClient } from 'redis';
4+
5+
async function getServerTime() {
6+
const client = createClient();
7+
await client.connect();
8+
9+
const serverTime = await client.time();
10+
// 2022-02-25T12:57:40.000Z { microseconds: 351346 }
11+
console.log(serverTime);
12+
13+
await client.quit();
14+
}
15+
16+
getServerTime();

packages/client/lib/commands/TIME.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface TimeReply extends Date {
99
export function transformReply(reply: [string, string]): TimeReply {
1010
const seconds = Number(reply[0]),
1111
microseconds = Number(reply[1]),
12-
d: Partial<TimeReply> = new Date(seconds + Math.round(microseconds / 1000));
12+
d: Partial<TimeReply> = new Date(seconds * 1000 + microseconds / 1000);
1313
d.microseconds = microseconds;
1414
return d as TimeReply;
1515
}

0 commit comments

Comments
 (0)