ボクココ

個人開発に関するテックブログ

RailsConf 20120425

Redis Application Patterns in Rails


Redis on Rails
simple get and set query
sample codes: http://github.com/obie/redis_on_rails

$ localtunel 3000

KEYS
construct key -> hash

Use Nest
github.com/soveran/nest
*creates a redis onnection by default
*calls to_s for key representation
string extention

Nest.class_eval do
def intialize key, redis=$resds
end

sample codes
key = Nest.new("foo")
key[:people]
c = Conference.first
c.rdb
c.rdb[:capacity].set "59"


It is required to write some setup code: ActiveRecord:Base
class AttendeeConferenceEvent < Event
def getter and setter useing redis

data_types
String, List, Set, Sorted Set, Hash

c.rdb[:user_ids]
c.rdb[:userids].smembers
-> []
c.rdb[:userids].sadd 1
c.rdb[:userids].sadd 2
c.rdb[:userids].sadd 3
c.rdb[:userids].smembers
-> [1,2,3]

redis command line
$ redis-cli -p 9999
get "Conference:8:capacity"
"monitor"
monitor every access to redis

Attendee.find_all_ny_id(rdb[:..])

We can realize association using ActiveRecord

http;//gihhub.com/obie/redis_props
easy annotation of activerecord objects. extracted

useful active record command
find_or_create_by..

redis_props method

  • > meta programming define attr automatically

RedisObjects
Map Redis types directly to ruby objects
github.com/nateware/redis-objects



Basecamp Next: Code Spelunking


if you want to write codes in ApplicationController,
use ActiveSupport::consern. and include them.

_.bind() will be your best friend.

Rails3.2.3
Tagged logger

MiniTest: Refactoring Test Unit and RSpec back to version 0.0.1


Simple Code is better
short method
moderately clear

Red Green Refactor cycle
MiniTest.. it is simple

Extending Ruby with Ruby


Meta programming
optimize fibonacci algorythm
activesupport::memoizable.memoize :fib

lazy evaluation