Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I name and store my dataset in redis?

I'm not understanding how to make a persistent store in Redis. Using the options hash is the only place I saw to pass in a path, and it doesn't 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" 
like image 502
Jeremy Smith Avatar asked May 04 '11 22:05

Jeremy Smith


People also ask

How do I permanently store data in Redis?

Redis does provide some mechanism to make the data persistance(permanent). There are three different ways to make Redis persistant: RDB, AOF and SAVE command. RDB Mechanism: RDB makes a copy of all the data in memory and stores them in secondary storage(permanent storage). This happens in a specified interval.

How do I store an object in Redis?

Object Storing Procedure. In the Redis, Everything can be stored as only key-value pair format. Key must be unique and storing an object in a string format is not a good practice anyway. Objects are usually stored in a binary array format in the databases.

Can you store files in Redis?

You can store the binary file in filesystem and then store the path to the file in redis. This is the recommended method if you want to manage binary data with redis. You can also store binary files/data directly inside redis. Redis keys and values don't have to be text strings.

How are values stored in Redis?

redis is an in-memory, key/value store. Think of it as a dictionary with any number of keys, each of which has a value that can be set or retrieved. However, Redis goes beyond a simple key/value store as it is actually a data structures server, supporting different kinds of values.


1 Answers

Redis is already a persistent store, and the :path option you found is to designate a unix socket to use to talk to the running Redis server in lieu of a TCP connection (supported in Redis 2.2), not to designate an actual database file.

Are you trying to be able to have isolated databases, so that when you set r['foo'] = 'bar', s['foo'] still returns nil?

If so, Redis lets you connect to multiple numbered databases, the default being #0 (this is what the /0 is in connected to redis://127.0.0.1:6379/0). To choose a different database:

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
like image 105
Dylan Markow Avatar answered Oct 26 '22 01:10

Dylan Markow