There is two popular gem for adding namespace to redis : redis-namespace and Nest, if i really understand we need namespace when we use the same instance server of redis with different projects, if i'm right this means : if i have project-1 and project-2 and each of these projects use my local redis storage, then perhaps the two projects have a users key which represente users of my app, so to prevent the conflict i need to namespace users key with something like the name of project :
for project-1 :
project-1:users
for project-1
project-2:users
if my above understand is not wrong, we can use redis-namespace gem
to solve this like this :
r = Redis::Namespace.new(:project-1, :redis => @r)
r['users']['joe']['email'] = 'joe@example.com'
and for the second project (project-2) just need to change project-1 to project-2 when instantiate new Redis::Namespace :
r = Redis::Namespace.new(:project-2, :redis => @r)
r['users']['joe']['email'] = 'joe@example.com'
please tell me if i'm not wrong in all this above explanation !
we can now continue with Nest :
from documentation we have this example :
Nest helps you generate keys by providing chainable namespaces that are already connected to Redis:
>> event = Nest.new("event")
>> event[3][:attendees].sadd("Albert")
>> event[3][:attendees].smembers
=> ["Albert"]
but here i'm not sure if Nest help us to do the same thing as redis-namespace or help us just to generate a chainable keys ???
what is exactly the difference between redis-namespace and Nest ?