jamesls/fakeredis

Adding support for TIME command

lknix opened this issue · 3 comments

lknix commented

After a quick glance it seems something like this should be added to FakeSocket class in order to support the command:

import time

@command(())
def time(self):
  return bytes(time.time()).split(".")

NOTE: I know there are microsecond precission issues with time on Windows (python 2.x), but it's probably good enough for what we want here.

I can open a PR if this is the right approach.

The interface looks like the right basic idea (from what I can recall - it's been a while since I touched this), but the implementation will need to actually split the float into integer and fractional components; otherwise it will get a very wrong answer if the result has more or less than microsecond precision, and can also end up with leading zeros.

lknix commented

@bmerry yes, you're correct - didn't really pay attention to float when writing the snippet above. Sounds like either using decimal with time or using datetime is the way to do it.

I guess I forgot to say at the time: a PR is welcome.