How do I name and save a dataset in redis?

I do not understand how to make a permanent store in Redis. Using the options hash is the only place I've seen to go along the way, and this does not seem to have any effect.

> r = Redis.new({:options => {:path => '~/redis_store'}})
=> #<Redis client v2.2.0 connected to redis://127.0.0.1:6379/0 (Redis v2.9.0)> 
> r['foo']
=> "bar" 
> s = Redis.new({:options => {:path => '~/redis_store2'}})
 => #<Redis client v2.2.0 connected to redis://127.0.0.1:6379/0 (Redis v2.9.0)> 
> s['foo']
=> "bar" 
+5
source share
1 answer

Redis is already persistent storage, and the parameter :pathyou found is to specify the unix socket to use to work with the Redis server instead of the TCP connection (supported in Redis 2.2), and not to indicate the actual database file.

You are trying to have a separate database, so that when you install r['foo'] = 'bar', s['foo']still returns nil?

, Redis , # 0 ( , /0 connected to redis://127.0.0.1:6379/0). :

r = Redis.new
=> #<Redis client v2.2.0 connected to redis://127.0.0.1:6379/0 (Redis v2.9.0)> 
r['foo'] = 'bar'

s = Redis.new(:db => 1)
=> #<Redis client v2.2.0 connected to redis://127.0.0.1:6379/1 (Redis v2.9.0)> 
s['foo']
# => nil
+9

All Articles