What is the average difference between Nest sockets and redis-namespace when we use redis with rails / rubies

There are two popular stones for adding a namespace in redis: redis-namespace and Nest , if I really understand that we need a namespace when we use the same redis instance server with different projects, if I'm right, that means: if I have there is project-1 and project-2, and each of these projects uses my local redis repository, then maybe two projects have a user key that represents the users of my application, so to prevent a conflict, I need to proxy the user key with something- something like and Yeni project:

for project 1:

project-1:users 

for project-1

 project-2:users 

if my understanding is not correct above, we can use the redis-namespace gem to solve this problem as follows:

 r = Redis::Namespace.new(:project-1, :redis => @r) r['users']['joe']['email'] = ' joe@example.com ' 

and for the second project (project-2), you just need to change project-1 to project-2 when creating a new Redis :: Namespace:

  r = Redis::Namespace.new(:project-2, :redis => @r) r['users']['joe']['email'] = ' joe@example.com ' 

please tell me if I am not mistaken in all this above explanation!

Now we can continue with Nest:

from the documentation we have this example:

Nest helps generate keys by providing chain namespaces that are already connected to Redis:

 >> event = Nest.new("event") >> event[3][:attendees].sadd("Albert") >> event[3][:attendees].smembers => ["Albert"] 

but here I am not sure that Nest will help us do the same thing as redis-namespace, or help us just create replaceable keys.

What is the difference between redis-namespace and Nest?

+1
source share
2 answers

Disclaimer: I am the author of Nest.

You can do the same with both libraries, and I think the main difference between these tools is their internal complexity. Although Nest helps you present a flat-key structure, Redis :: Namespace has a translation table for each command and therefore is more fragile and intense.

Take a look at the source code of both tools to see what I mean:

https://github.com/soveran/nest/blob/master/lib/nest.rb

https://github.com/resque/redis-namespace/blob/master/lib/redis/namespace.rb

However, the correct solution to the problem you described is to have separate Redis instances for different projects. Keep in mind that the keyspace is only one aspect to consider (which can also be easily solved using the different databases provided by Redis). Other aspects (conservation strategy, communication and memory restrictions, key evictions, etc.) are usually configured depending on the nature of the project.

Another important fact is that Redis is single-threaded, and in many applications it is used to share the same kernel for all requests. With that in mind, having different instances of Redis helps you parallelize your work.

+1
source

Do you know http://redis.io/commands/select for parallel operation of several databases on one server? Here you have no key conflict and the databases are separated. Only if you immediately get access to keys from all databases is this impossible.

0
source

Source: https://habr.com/ru/post/952937/


All Articles