I am learning Redis. I am able to set and get key, value pairs using Ruby Client for Redis.
I am now trying to store and load dump.rdb from custom path. I performed the following steps:
- I programmatically set the directory for dump.rdb in my ruby script.
- I then have an option to create fresh data or load existing data.
- I created fresh data while executing my ruby script the first time.
- I ran my ruby script again and load existing data this time around. The output is as expected.
However, when i restart redis server and run the same ruby script (which again, programmatically sets the directory for dump.rdb) and try to load the data, it does not do so.
Is there a way to programmatically get the redis server to load dump.rdb after i set 'dir' parameter in the config?
I have looked at Redis Ignoring directory in redis.conf and tried searching on google for this. There is always the option of setting the path to the dump.rdb in redis.conf, but i wish to do it programmatically.
My Ruby Code is as follows:
require 'redis'
client = Redis.new
client.config('set', 'dir', '/tmp')
puts 'Enter load(to load existing data) or new(to create new data)'
print 'prompt>'
command = gets.chomp
if command == 'new'
client.flushdb
client.set('key1', 'value1')
client.set('key2', 'value2')
client.save
else
puts client.get('key1')
puts client.get('key2')
end
Here is the output of executing the ruby script:
laptop:~/ruby/workspace$ ruby test.rb
Enter load(to load existing data) or new(to create new data)
prompt>new
laptop:~/ruby/workspace$ ruby test.rb
Enter load(to load existing data) or new(to create new data)
prompt>load
value1
value2
# Now i restart redis-server
laptop:~/ruby/workspace$ ruby test.rb
Enter load(to load existing data) or new(to create new data)
prompt>load
# No output is printed
Software Details:
- OS: Ubuntu Linux 12.04 64 bit
- Redis version 2.6.9 running in default configuration on localhost
- Ruby: version 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
Please let me know if you require any additional information from my part.