Class: RedisLoad::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/redis-load/command_line.rb

Overview

This class acts as an adapter, taking parameters and environment variables and using those to drive an instance of RedisLoad::Loader

Instance Method Summary collapse

Constructor Details

#initialize(opts, env) ⇒ CommandLine

Returns a new instance of CommandLine.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/redis-load/command_line.rb', line 7

def initialize(opts, env)
  @opts = opts
  @env = env
  
  opts = Hash.new
  opts[:host] = @opts["host"] if @opts["host"]
  opts[:port] = @opts["port"] if @opts["port"]
  opts[:db] = @opts["database"] if @opts["database"]
  opts[:password] = @opts["password"] if @opts["password"]              
    
  @redis = Redis.new(opts)
  @loader = RedisLoad::Loader.new(@redis)
            
end

Instance Method Details

#load_jsonObject



22
23
24
25
26
# File 'lib/redis-load/command_line.rb', line 22

def load_json()
  puts "Loading data from JSON file #{@opts["file"]} into server"
  counter = @loader.load_json( @opts["file"], @opts["jsonpath"] )
  puts "#{counter} keys loaded."      
end

#load_keysObject



40
41
42
43
44
# File 'lib/redis-load/command_line.rb', line 40

def load_keys()
  puts "Loading keys from #{@opts["file"]} into server"
  counter = @loader.load_keys( @opts["file"] )
  puts "#{counter} lines loaded."
end

#load_listObject



28
29
30
31
32
# File 'lib/redis-load/command_line.rb', line 28

def load_list()
  puts "Loading #{@opts["file"]} into list #{@opts["key"]} into server"
  counter = @loader.load_list( @opts["key"] , @opts["file"] )
  puts "#{counter} lines loaded."
end

#load_setObject



46
47
48
49
50
# File 'lib/redis-load/command_line.rb', line 46

def load_set()
  puts "Loading #{@opts["file"]} into set #{@opts["key"]} on server"
  counter @loader.load_set( @opts["key"], @opts["file"] )
  puts "#{counter} lines loaded."
end

#load_zsetObject



65
66
67
68
69
# File 'lib/redis-load/command_line.rb', line 65

def load_zset()
  puts "Loading #{@opts["file"]} into sorted set #{@opts["key"]} on server"
  counter = @loader.load_zset( @opts["key"], @opts["file"] )
  puts "#{counter} items loaded."
end

#save_jsonObject



52
53
54
55
56
57
# File 'lib/redis-load/command_line.rb', line 52

def save_json()      
  puts "Saving json into #{@opts["file"]}"
  keys = @opts["keys"] || "*"      
  counter = @loader.save_json( @opts["file"], keys )
  puts "#{counter} keys saved."      
end

#save_listObject



34
35
36
37
38
# File 'lib/redis-load/command_line.rb', line 34

def save_list()
  puts "Saving list #{@opts["key"]} into #{@opts["file"]}"
  size = @loader.save_list( @opts["key"], @opts["file"] )
  puts "#{size} lines saved."      
end

#save_setObject



59
60
61
62
63
# File 'lib/redis-load/command_line.rb', line 59

def save_set()
  puts "Saving set #{@opts["key"]} into #{@opts["file"]}"
  size = @loader.save_set( @opts["key"], @opts["file"] )
  puts "#{size} items saved."      
end

#save_zsetObject



71
72
73
74
75
# File 'lib/redis-load/command_line.rb', line 71

def save_zset()
  puts "Saving set #{@opts["key"]} into #{@opts["file"]}"
  size = @loader.save_zset( @opts["key"], @opts["file"] )
  puts "#{size} items saved."  
end