Gem Rediscord: 在 redis set/zset 中同步数据主键

kikyous · 2016年08月03日 · 1580 次阅读

Rediscord https://github.com/kikyous/rediscord

keep record id sync with dynamic redis set or zset

Install

add gem 'rediscord' to Gemfile, and run bundle install

Example

  • set ```ruby class Post < ApplicationRecord enum level: [ :one, :two, :there ]

include Rediscord redis_set key: ->(m){ "level_#{m.level}_post_set" }, redis: Redis.new end

```ruby
Post.create(level: :one)   # id: 1
Post.create(level: :one)   # id: 2
Post.create(level: :two)   # id: 3
Post.create(level: :there) # id: 4

what's in redis?

  • zset
class Post < ApplicationRecord
  enum level: [ :one, :two, :there ]

  include Rediscord
  redis_zset key: ->(m){ "level_#{m.level}_post_zset" }, score: ->(m){ m.updated_at.to_i }, redis: Redis.new
end
Post.create(level: :one)
Post.create(level: :one)
Post.create(level: :two)
Post.create(level: :there)

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