27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/prop2redis.rb', line 27
def self.main
abort "Usage: prop2redis <propertyfile>" if ARGV.length != 1
property_file = ARGV[0]
abort "Property file must exist." if !File.exist?(property_file)
abort "Property file must be a file." if !File.file?(property_file)
redis_url = ENV['REDIS_URL']
abort "REDIS_URL environment variable must be set" if redis_url.nil?
URI uri = URI(redis_url)
abort "REDIS_URL must have scheme 'redis'." if uri.scheme != 'redis'
abort "REDIS_URL must have a namespace query parameter." if ( uri.query.nil? )
query = uri.query
query_hash = CGI::parse(query)
abort "REDIS_URL must have a namespace query parameter." if (query_hash['namespace'].nil?)
namespace=query_hash['namespace']
abort "REDIS_URL must have a path." if uri.path.nil?
hash = load_properties(property_file)
db = uri.path
host = uri.host
port = uri.port.nil? ? 6379 : uri.port
db = uri.path
redis = Redis.new(:host=>host, :port=>port, :db=>db)
redis.multi do
hash.each do |key, value|
redis.hset namespace, to_env_format(key), value
end
end
end
|