带Redis的MongoDB [英] MongoDB with redis

查看:93
本文介绍了带Redis的MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以举出示例使用案例,说明您将从Redis和MongoDB一起使用时会受益吗?

Can anyone give example use cases of when you would benefit from using Redis and MongoDB in conjunction with each other?

推荐答案

Redis和MongoDB可以一起使用,效果很好. Craiglist是一家以运行MongoDB和Redis(以及MySQL和Sphinx)而闻名的公司.参见此演示文稿来自Jeremy Zawodny.

Redis and MongoDB can be used together with good results. A company well-known for running MongoDB and Redis (along with MySQL and Sphinx) is Craiglist. See this presentation from Jeremy Zawodny.

MongoDB对于以各种方式建立索引的,面向文档的持久数据很有趣.对于易失性数据或对延迟敏感的半永久性数据,Redis更有趣.

MongoDB is interesting for persistent, document oriented, data indexed in various ways. Redis is more interesting for volatile data, or latency sensitive semi-persistent data.

以下是在MongoDB之上具体使用Redis的一些示例.

Here are a few examples of concrete usage of Redis on top of MongoDB.

  • 2.2之前的MongoDB尚无过期机制.上限集合不能真正用于实现真正的TTL. Redis具有基于TTL的过期机制,可以方便地存储易失性数据.例如,用户会话通常存储在Redis中,而用户数据将存储在MongoDB中并建立索引.请注意,MongoDB 2.2在集合级别引入了一种低精度的过期机制(例如,用于清除数据).

  • Pre-2.2 MongoDB does not have yet an expiration mechanism. Capped collections cannot really be used to implement a real TTL. Redis has a TTL-based expiration mechanism, making it convenient to store volatile data. For instance, user sessions are commonly stored in Redis, while user data will be stored and indexed in MongoDB. Note that MongoDB 2.2 has introduced a low accuracy expiration mechanism at the collection level (to be used for purging data for instance).

Redis提供了方便的集合数据类型及其关联的操作(联合,交集,多个集合的差等).在此功能之上实现基本的多面搜索或标记引擎非常容易,这是对MongoDB更传统的索引功能的有趣补充.

Redis provides a convenient set datatype and its associated operations (union, intersection, difference on multiple sets, etc ...). It is quite easy to implement a basic faceted search or tagging engine on top of this feature, which is an interesting addition to MongoDB more traditional indexing capabilities.

Redis支持有效地阻止列表上的弹出操作.这可用于实现临时分布式排队系统.它比MongoDB可尾游标IMO更具灵活性,因为后端应用程序可以侦听超时的几个队列,原子地将项目转移到另一个队列,等等...如果应用程序需要排队,则将队列存储在Redis中是有意义的,并将持久性功能数据保留在MongoDB中.

Redis supports efficient blocking pop operations on lists. This can be used to implement an ad-hoc distributed queuing system. It is more flexible than MongoDB tailable cursors IMO, since a backend application can listen to several queues with a timeout, transfer items to another queue atomically, etc ... If the application requires some queuing, it makes sense to store the queue in Redis, and keep the persistent functional data in MongoDB.

Redis还提供了发布/订阅机制.在分布式应用程序中,事件传播系统可能会有用.对于持久性数据保留在MongoDB中而言,这再次是Redis的绝佳用例.

Redis also offers a pub/sub mechanism. In a distributed application, an event propagation system may be useful. This is again an excellent use case for Redis, while the persistent data are kept in MongoDB.

由于使用MongoDB设计数据模型要比使用Redis容易得多(Redis更为底层),因此可以从MongoDB的主要持久性数据灵活性以及Redis提供的额外功能中受益(低延迟,项目过期,队列,发布/订阅,原子块等).确实是一个很好的组合.

Because it is much easier to design a data model with MongoDB than with Redis (Redis is more low-level), it is interesting to benefit from the flexibility of MongoDB for main persistent data, and from the extra features provided by Redis (low latency, item expiration, queues, pub/sub, atomic blocks, etc ...). It is indeed a good combination.

请注意,您永远不要在同一台机器上运行Redis和MongoDB服务器. MongoDB内存被设计为可以换出,Redis不是.如果MongoDB触发某些交换活动,则Redis的性能将是灾难性的.它们应该隔离在不同的节点上.

Please note you should never run a Redis and MongoDB server on the same machine. MongoDB memory is designed to be swapped out, Redis is not. If MongoDB triggers some swapping activity, the performance of Redis will be catastrophic. They should be isolated on different nodes.

这篇关于带Redis的MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆