Rails Rails 能使用 Redis 的 counter 字段排序吗?

schwinn · 2015年01月09日 · 最后由 xiaoronglv 回复于 2015年01月09日 · 2165 次阅读
class Serve
  include Mongoid::Document
  include Mongoid::Timestamps
  include Redis::Objects

  field :name, type: String
  field :serve_type, type: String

  ## 接收消息的条数
  counter :t_receive
  ## 发送消息的条数
  counter :t_send

  belongs_to :itemable, polymorphic: true
  belongs_to :user
end

我想以计数器进行排序,执行Serve.desc(:t_receive).page(params[:page]).per(10) 但是返回的集合是随机的 不是按t_receive字段排序的。求高见!

你这个数据又不热,干嘛用 redis?

不如用个 sorted set

key: serve id score :count

需要 登录 后方可回复, 如果你还没有账号请 注册新账号