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

schwinn · January 09, 2015 · Last by xiaoronglv replied at January 09, 2015 · 2167 hits
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

You need to Sign in before reply, if you don't have an account, please Sign up first.