Module: Redis::Helper

Included in:
Migrator, PipeMigrator, Populator
Defined in:
lib/redis_migrator/redis_helper.rb

Instance Method Summary collapse

Instance Method Details

#parse_redis_url(redis_url) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/redis_migrator/redis_helper.rb', line 9

def parse_redis_url(redis_url)
  node = URI(redis_url)
  path = node.path
  db = path[1..-1].to_i rescue 0

  {
    host: node.host,
    port: node.port || 6379,
    db:   db
  }
end

#to_redis_proto(*cmd) ⇒ Object



3
4
5
6
7
# File 'lib/redis_migrator/redis_helper.rb', line 3

def to_redis_proto(*cmd)
  cmd.inject("*#{cmd.length}\r\n") {|acc, arg|
    acc << "$#{arg.to_s.bytesize}\r\n#{arg}\r\n"
  }
end