Redis

1,055 views
983 views

Published on

About redis and how we used to implement stateful widgets in our project of e-learning system ALEF and to allow for background logging with the help of resque.

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,055
On SlideShare
0
From Embeds
0
Number of Embeds
65
Actions
Shares
0
Downloads
13
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Redis

  1. 1. @robo_moro
  2. 2. redis• In-memory key-value store• Master-slave replication• Persistence – RDB (snapshots) – AOF (append-only log file)• Supported languages – Ruby, Python, Java, C, PHP, Javascript (Node.js)
  3. 3. redis• Data types – String, List, Set, Hash, Sorted set• Used in – Engine Yard, Github, stackoverflow, …
  4. 4. redis• Data types – String, List, Set, Hash, Sorted set• Used in – Engine Yard, Github, stackoverflow, … ALEF
  5. 5. ALEF = Adaptive LEarning Framework
  6. 6. ALEF stateful widgets• Asynchronous initialization & callbacks• Problem – The action1 servicing widget1 loads the current session – The action2 servicing widget2 loads the current session – action1 makes some changes to its copy of the session – action2 makes some changes to its copy of the session – action2 completes and saves its changed session data – action1 completes and saves its changed session data
  7. 7. ALEF stateful widgets• Asynchronous initialization & callbacks• Problem – The action1 servicing widget1 loads the current session – The action2 servicing widget2 loads the current session – action1 makes some changes to its copy of the session – action2 makes some changes to its copy of the session – action2 completes and saves its changed session data – action1 completes and saves its changed session data• action1 destroys the changes made by action2
  8. 8. ALEF stateful widgetsclass WidgetController < ApplicationController include WidgetManager before_filter :get_user_widget_id, :get_persistent after_filter :set_persistentenddef get_persistent $redis.hgetall(@widget_id).symbolize_keys.each do |key, value| if @persistent.include? key self.instance_variable_set key, Marshal.load(value) end endend
  9. 9. ALEF stateful widgetsdef set_persistent to_persist = Hash.new @persistent.each do |key| to_persist[key] = Marshal.dump(self.instance_variable_get(key)) end $redis.mapped_hmset @widget_id, to_persistend
  10. 10. ALEF background jobs• We log everything• We process logs to update user model• Solution – resque + redis – resque-poolResque.redis = Redis.new((config.symbolize_keys))Resque.enqueue(KnowledgeModellerJob, session[:user_id], @lo.id, @user_answer[:right])
  11. 11. ALEF background jobsclass KnowledgeModellerJob @queue = :knowledge_modellers def self.perform(user_id, lo_id, params) student = User.find_by_id user_id lo = LearningObject.find_by_id lo_id KnowledgeModeller.new. question_response(student, lo, params) endend

×