class MockRedis
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
Defines the gem version.
Constants
- DEFAULTS
- DUMP_TYPES
- VERSION
- WouldBlock
Attributes
Public Class Methods
Source
# 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
Public Instance Methods
Source
# File lib/mock_redis.rb, line 48 def id "redis://#{host}:#{port}/#{db}" end
Also aliased as: location
Source
# File lib/mock_redis.rb, line 99 def initialize_copy(source) super @db = @db.clone end
Calls superclass method
Source
# File lib/mock_redis.rb, line 93 def method_missing(method, *args, &block) logging([[method, *args]]) do @db.send(method, *args, &block) end end
Source
# File lib/mock_redis.rb, line 89 def respond_to?(method, include_private = false) super || @db.respond_to?(method, include_private) end
Calls superclass method
Source
# File lib/mock_redis.rb, line 69 def time_at(timestamp) options[:time_class].at(timestamp) end
Protected Instance Methods
Source
# File lib/mock_redis.rb, line 106 def _parse_options(options) return DEFAULTS.dup if options.nil? defaults = DEFAULTS.dup url = options[:url] || ENV['REDIS_URL'] # Override defaults from URL if given if url require 'uri' uri = URI(url) if uri.scheme == 'unix' defaults[:path] = uri.path else # Require the URL to have at least a host raise ArgumentError, 'invalid url' unless uri.host defaults[:scheme] = uri.scheme defaults[:host] = uri.host defaults[:port] = uri.port if uri.port defaults[:password] = uri.password if uri.password defaults[:db] = uri.path[1..].to_i if uri.path end end options = defaults.merge(options) if options[:path] options[:scheme] = 'unix' options.delete(:host) options.delete(:port) else options[:host] = options[:host].to_s options[:port] = options[:port].to_i end options[:timeout] = options[:timeout].to_f options[:db] = options[:db].to_i options end
Source
# File lib/mock_redis.rb, line 150 def logging(commands) return yield unless logger&.debug? begin commands.each do |name, *args| logged_args = args.map do |a| if a.respond_to?(:inspect) then a.inspect elsif a.respond_to?(:to_s) then a.to_s else # handle poorly-behaved descendants of BasicObject klass = a.instance_exec { (class << self; self end).superclass } "\#<#{klass}:#{a.__id__}>" end end logger.debug("[MockRedis] command=#{name.to_s.upcase} args=#{logged_args.join(' ')}") end t1 = Time.now yield ensure if t1 logger.debug(format('[MockRedis] call_time=%<time>0.2f ms', time: ((Time.now - t1) * 1000))) end end end