class Redis::Connection::Ruby

Constants

ELASTICACHE_LOADING_ERROR_PREFIX
ELASTICACHE_LOADING_MESSAGE
ELASTICACHE_READONLY_ERROR_PREFIX
ELASTICACHE_READONLY_MESSAGE

Public Instance Methods

format_error_reply(line) click to toggle source

Amazon Elasticache supports failover, but because it uses DNS magic to point to the master node, TCP connections are not disconnected and we can issue write operations to a node that is no longer the master. Under normal conditions this should be interpreted as a `CommandError`, but with Elasticache replication groups, we should consider this a `BaseConnectionError` so we terminate the connection, reconnect and retry the operation with the correct node as the master accepting writes.

# File lib/redis/elasticache/failover.rb, line 19
def format_error_reply(line)
  error_message = line.strip
  if error_message_has_prefix?(ELASTICACHE_READONLY_ERROR_PREFIX, error_message)
    raise BaseConnectionError, ELASTICACHE_READONLY_MESSAGE
  elsif error_message_has_prefix?(ELASTICACHE_LOADING_ERROR_PREFIX, error_message)
    raise BaseConnectionError, ELASTICACHE_LOADING_MESSAGE
  else
    CommandError.new(error_message)
  end
end

Private Instance Methods

error_message_has_prefix?(prefix, error_message) click to toggle source
# File lib/redis/elasticache/failover.rb, line 31
def error_message_has_prefix?(prefix, error_message)
  (error_message.slice(0, prefix.length) === prefix)
end