Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Redis with Ruby

Redis with Ruby

C1194b5728c155e195b223d91e1b0d77?s=128

Damian Le Nouaille

April 04, 2012
Tweet

Transcript

  1. None
  2. 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’
  3. USE Cache Session (cookies) gem ‘redis-rails’ App::Application.config.session_store :redis_store, :servers =>

    "redis://127.0.0.1:6379/1"
  4. 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’)
  5. ENVIRONMENT Resque (+ Scheduler) Ohm EventMachine PubSub

  6. Resque (+Scheduler) Fast ² Queue YAML - Cron gem ‘resque’

    gem ‘resque-scheduler’, git: 'git://github.com/bvandenbos/resque-scheduler'
  7. Ohm ORM Flexible Extensible gem ‘ohm’ gem ‘ohm-contrib’

  8. 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
  9. Ohm (model) class User < Ohm::Model def persisted? false end

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

    extend ActiveModel::Naming include ActiveModel::AttributeMethods index :content reference :user, User end
  11. EventMachine Node.js for Ruby em-WebSocket em-redis gem ‘eventmachine’ gem ‘em-redis’

  12. 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’)
  13. PRODUCTION Debian / OSX Heroku Easy (foreman)

  14. @ damln www.dln.name