diff --git a/lib/mock_redis.rb b/lib/mock_redis.rb index d8d8eaa6..3e94e31a 100644 --- a/lib/mock_redis.rb +++ b/lib/mock_redis.rb @@ -64,13 +64,6 @@ def db options[:db] end - def now - current_time = options[:time_class].now - miliseconds = (current_time.to_r - current_time.to_i) * 1_000 - [current_time.to_i, miliseconds.to_i] - end - alias time now - def time_at(timestamp) options[:time_class].at(timestamp) end diff --git a/lib/mock_redis/database.rb b/lib/mock_redis/database.rb index 383d4abe..e4b5c4d9 100644 --- a/lib/mock_redis/database.rb +++ b/lib/mock_redis/database.rb @@ -159,7 +159,7 @@ def scan_each(opts = {}, &block) end def lastsave - @base.now.first + now.first end def persist(key) @@ -240,6 +240,13 @@ def pttl(key) end end + def now + current_time = @base.options[:time_class].now + miliseconds = (current_time.to_r - current_time.to_i) * 1_000 + [current_time.to_i, miliseconds.to_i] + end + alias time now + def type(key) if !exists(key) 'none' @@ -344,7 +351,7 @@ def zero_pad(string, desired_length) # This method isn't private, but it also isn't a Redis command, so # it doesn't belong up above with all the Redis commands. def expire_keys - now, miliseconds = @base.now + now, miliseconds = self.now now_ms = now * 1_000 + miliseconds to_delete = expire_times.take_while do |(time, _key)| diff --git a/spec/commands/pipelined_spec.rb b/spec/commands/pipelined_spec.rb index 6c8461f0..cb9dfb2c 100644 --- a/spec/commands/pipelined_spec.rb +++ b/spec/commands/pipelined_spec.rb @@ -66,6 +66,26 @@ end end + context 'with redis time return value' do + let(:time_stub) { double 'Time', :now => Time.new(2019, 1, 2, 3, 4, 6, '+00:00') } + let(:options) { { :time_class => time_stub } } + + subject { MockRedis.new(options) } + + it 'returns the time value' do + subject.set('foo', 'bar') + + results = subject.pipelined do + subject.get('foo') + subject.host # defined on MockRedis, so not captured + subject.time + subject.echo('baz') + end + + expect(results).to eq(['bar', [1_546_398_246, 0], 'baz']) + end + end + context 'with nested pipelines' do let(:key1) { 'hello' } let(:key2) { 'world' }