How to use the Redis store on the Ruby on Rails _ruby topic

Source: Internet
Author: User
Tags memory usage redis ruby on rails

Redis Store is a toolkit designed for Ruby applications that supports fragmentation, master-slave copying, marshalling, and timeouts and namespaces. In addition, it is also very easy to use on the Ruby on Rails.
How to use:
for using the Redis Store on rails, first we need to add a portal to the Gemfile file

Gem ' redis-rails '
gem ' redis-rack-cache ' # optional

Then we will have the following choices:

# # Cache Store
# config/environments/production.rb
config.cache_store =: Redis_store
 
# # Session Store
# config/initializers/session_store.rb
Myapplication::application.config.session_store:redis_store,
servers: [' redis://:secret@192.168.6.23:6379/ 0 ', ' REDIS://:SECRET@192.168.6.99:6379/1 ']
 
# # HTTP Cache
# config.ru
require ' rack '
require ' Rack/cache '
require ' redis-rack-cache ' use
 
rack::cache,
metastore: ' redis://localhost:6379/0/ Metastore ',
entitystore: ' Redis://localhost:6380/0/entitystore '

As you can see, using this plugin is fairly straightforward, but now I'm going to show you how to manage these settings.
The first case speaks for itself, and we say we use Activesupport to load the Redis Store. Keep in mind that Redis's contraire only supports strings, so you can use serialization and deserialization techniques to store any object.

The second case here is a little bit more complicated. First, we need to use a server cluster. Again, the Redis store supports fragmentation, which means that HTTP sessions are transparently visible between the two servers.

The final case is mainly about Ruby's HTTP caching proxies, which are designed to speed up HTTP responses, and also store meta data and entity entity objects in a name-value pair, and mention here that if we're storing plain string literals, Mashalling modules also do not need to be started.

Despite all that, the above points are just a small part of all the Redis store's features, but it also supports Rack,sinatra and i18n.

Summarize

I personally think that Redis is basically your server environment must use a plug-in, it is fast and can use a wide range, such as database, caching, slicing machine and so on, it is a good tool. However, there is a cost to any benefit: like rails, you have to spend a lot of time and installation and configuration to find the perfect balance between performance and memory usage.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.