Redis with Ruby

Redis with Ruby

Damian Le Nouaille

April 04, 2012

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

14 slides
  1. REDIS Redis is an open source, advanced key- value store.

    It is often referred to as a data structure server since keys can contain strings, hashes,lists, sets and sorted sets. gem ‘redis’
  2. Commands $redis = new Redis(:host => ‘127.0.0.7’, :port => 6379,

    :db => 0) $redis.set(‘my_key’, ‘awesome’) $redis.get(‘my_key’) => ‘awesome’ $redis.del(‘my_key’)
  3. Resque (+Scheduler) Fast ² Queue YAML - Cron gem ‘resque’

    gem ‘resque-scheduler’, git: 'git://github.com/bvandenbos/resque-scheduler'
  4. Ohm (model) class User < Ohm::Model attribute :name attribute :nickname

    include Ohm::Validations extend ActiveModel::Naming include ActiveModel::AttributeMethods index :name collection :messages, Message end
  5. Ohm (model) class User < Ohm::Model def persisted? false end

    def to_hash super.merge({:name => self.name}) end end
  6. Ohm (model) class Message < Ohm::Model attribute :content include Ohm::Validations

    extend ActiveModel::Naming include ActiveModel::AttributeMethods index :content reference :user, User end
  7. PubSub $redis = new Redis(:host => ‘127.0.0.7’, :port => 6379,

    :db => 0) $redis.publish(‘my_channel’, ‘content’) $redis.subscribe(‘my_channel’) do |on| on.message do |channel, msg| puts msg end end $redis.publish(‘my_channel.*’, ‘content’)

More Decks by Damian Le Nouaille

Other Decks in Programming