Skip to content

Fixes the time command response. #2008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This folder contains example scripts showing how to use Node Redis in different
| `connect-as-acl-user.js` | Connect to Redis 6 using an ACL user |
| `count-min-sketch.js` | Estimate the frequency of a given event using the [RedisBloom](https://redisbloom.io) Count-Min Sketch |
| `cuckoo-filter.js` | Space efficient set membership checks with a [Cuckoo Filter](https://en.wikipedia.org/wiki/Cuckoo_filter) using [RedisBloom](https://redisbloom.io) |
| `get-server-time.js` | Get the time from the Redis server |
| `lua-multi-incr.js` | Define a custom lua script that allows you to perform INCRBY on multiple keys |
| `managing-json.js` | Store, retrieve and manipulate JSON data atomically with [RedisJSON](https://redisjson.io/) |
| `search-hashes.js` | Uses [RediSearch](https://redisearch.io) to index and search data in hashes |
Expand Down
16 changes: 16 additions & 0 deletions examples/get-server-time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Get the time from the Redis Server.

import { createClient } from 'redis';

async function getServerTime() {
const client = createClient();
await client.connect();

const serverTime = await client.time();
// 2022-02-25T12:57:40.000Z { microseconds: 351346 }
console.log(serverTime);

await client.quit();
}

getServerTime();
2 changes: 1 addition & 1 deletion packages/client/lib/commands/TIME.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface TimeReply extends Date {
export function transformReply(reply: [string, string]): TimeReply {
const seconds = Number(reply[0]),
microseconds = Number(reply[1]),
d: Partial<TimeReply> = new Date(seconds + Math.round(microseconds / 1000));
d: Partial<TimeReply> = new Date((seconds + Math.round(microseconds / 1000)) * 1000);
d.microseconds = microseconds;
return d as TimeReply;
}