English 中文(简体)
利用重新建立关于其 app库的数据库
原标题:using redis in place of a database on heroku app

我在她的空洞上有一个简单的信号。 基本用户在搜索术语上出现和类型。 我愿在该页边增加一段,显示最近的搜索。 虽然我只是想在我的申请中增加一个数据库。 我已经读过重,但是,这是否可用于? 我只能推一下重新拆散的10个最近搜索术语,并取回这些术语?

最佳回答

是的,这是重新处置的良好案例。 在红斯名单上删除搜索词,并在你想要显示这些词语时检索最后十条。 定期,除最后10个项目外,你可以将全部物品从名单上删除,以避免过多。

在名单上增列项目(假设<>REDIS)为红色链接:

REDIS.rpush( searches ,  Xyz )

并检索最后十大类:

REDIS.lrange( searches , -10, -1)

(作为副作用,Redis将首先获得名单的最后部分,这也许是你想要的。) Redis列出了诸如Rubya阵列之类的工作,负面指数意味着从尾就算出。

将名单限定在你可以使用这一指挥力的10个部分:

REDIS.ltrim( searches , -10, -1)

无论在你推动什么时候,你们都这样做,以确保名单永远不会增长,或者你们定期这样做。 <代码>lrange的运行意味着,你只能从任何方面收回最后10项内容,因此它只是一个偏好问题。

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签