Reputation: 93
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:
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:
Please let me know if you require any additional information from my part.
Upvotes: 1
Views: 1126
Reputation: 15773
I believe what you are after with regards to loading a "custom rdb" is to use the "config set" command to set the path to the dump file. Note it will need to be on the same host as the redis daemon for this to work. Once you've specified it using the above command your work isn't done. Redis doesn't read from the filesystem except on startup.
Thus, in order to do this you would need to have a supervisor process that restarts Redis. Then, you would need to
Even then, it would not work because upon startup the server will read the config from disk. I do not know of a command for Redis to save it's runtime configuration to disk, and do not believe it exists.
I'm not sure why you are trying this, but I am sure it won't work without coding outside of Redis to manage. Perhaps if you clarified why you think you need to do it this way we can be of better help.
Short of writing non-Redis code you could run multiple instances, with each configured to the dump file you need it to use; then select which one on the client side and use the appropriate one.
Upvotes: 1