Class: MockRedis

Inherits:
Object
  • Object
show all
Includes:
UndefRedisMethods
Defined in:
lib/mock_redis/version.rb,
lib/mock_redis.rb,
lib/mock_redis/zset.rb,
lib/mock_redis/future.rb,
lib/mock_redis/stream.rb,
lib/mock_redis/database.rb,
lib/mock_redis/stream/id.rb,
lib/mock_redis/assertions.rb,
lib/mock_redis/exceptions.rb,
lib/mock_redis/info_method.rb,
lib/mock_redis/set_methods.rb,
lib/mock_redis/sort_method.rb,
lib/mock_redis/hash_methods.rb,
lib/mock_redis/list_methods.rb,
lib/mock_redis/zset_methods.rb,
lib/mock_redis/expire_wrapper.rb,
lib/mock_redis/stream_methods.rb,
lib/mock_redis/string_methods.rb,
lib/mock_redis/utility_methods.rb,
lib/mock_redis/indifferent_hash.rb,
lib/mock_redis/multi_db_wrapper.rb,
lib/mock_redis/connection_method.rb,
lib/mock_redis/pipelined_wrapper.rb,
lib/mock_redis/geospatial_methods.rb,
lib/mock_redis/transaction_wrapper.rb,
lib/mock_redis/undef_redis_methods.rb

Overview

TODO: Implement the following commands

* xgroup
* xreadgroup
* xack
* xpending
* xclaim
* xinfo
* xtrim
* xdel

TODO: Complete support for

* xtrim
    - `approximate: true` argument is currently ignored
* xadd
    - `approximate: true` argument (for capped streams) is currently ignored

For details of these commands see

* https://redis.io/topics/streams-intro
* https://redis.io/commands#stream

Defined Under Namespace

Modules: Assertions, ConnectionMethod, GeospatialMethods, HashMethods, InfoMethod, ListMethods, SetMethods, SortMethod, StreamMethods, StringMethods, UndefRedisMethods, UtilityMethods, ZsetMethods Classes: Database, ExpireWrapper, Future, FutureNotReady, IndifferentHash, MultiDbWrapper, PipelinedWrapper, Stream, TransactionWrapper, Zset

Constant Summary collapse

DEFAULTS =
{
  :scheme => 'redis',
  :host => '127.0.0.1',
  :port => 6379,
  :path => nil,
  :timeout => 5.0,
  :password => nil,
  :logger => nil,
  :db => 0,
  :time_class => Time,
}.freeze
VERSION =
'0.29.0'
WouldBlock =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UndefRedisMethods

included

Constructor Details

#initialize(*args) ⇒ MockRedis

Returns a new instance of MockRedis.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mock_redis.rb', line 34

def initialize(*args)
  @options = _parse_options(args.first)

  @db = PipelinedWrapper.new(
    TransactionWrapper.new(
      ExpireWrapper.new(
        MultiDbWrapper.new(
          Database.new(self, *args)
        )
      )
    )
  )
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/mock_redis.rb', line 16

def options
  @options
end

Class Method Details

.connect(*args) ⇒ Object



30
31
32
# File 'lib/mock_redis.rb', line 30

def self.connect(*args)
  new(*args)
end

Instance Method Details

#call(command, &_block) ⇒ Object



53
54
55
# File 'lib/mock_redis.rb', line 53

def call(command, &_block)
  send(*command)
end

#clientObject



77
78
79
# File 'lib/mock_redis.rb', line 77

def client
  self
end

#connectObject



81
82
83
# File 'lib/mock_redis.rb', line 81

def connect
  self
end

#dbObject



65
66
67
# File 'lib/mock_redis.rb', line 65

def db
  options[:db]
end

#hostObject



57
58
59
# File 'lib/mock_redis.rb', line 57

def host
  options[:host]
end

#idObject Also known as: location



48
49
50
# File 'lib/mock_redis.rb', line 48

def id
  "redis://#{host}:#{port}/#{db}"
end

#initialize_copy(source) ⇒ Object



99
100
101
102
# File 'lib/mock_redis.rb', line 99

def initialize_copy(source)
  super
  @db = @db.clone
end

#loggerObject



69
70
71
# File 'lib/mock_redis.rb', line 69

def logger
  options[:logger]
end

#portObject



61
62
63
# File 'lib/mock_redis.rb', line 61

def port
  options[:port]
end

#reconnectObject



85
86
87
# File 'lib/mock_redis.rb', line 85

def reconnect
  self
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/mock_redis.rb', line 89

def respond_to?(method, include_private = false)
  super || @db.respond_to?(method, include_private)
end

#time_at(timestamp) ⇒ Object



73
74
75
# File 'lib/mock_redis.rb', line 73

def time_at(timestamp)
  options[:time_class].at(timestamp)
end