SlideShare una empresa de Scribd logo
1 de 12
Descargar para leer sin conexión
Frivol -  Frivolously simple temporary storage backed by Redis ,[object Object],[object Object]
Usage
Implementation
Problems
Future Development
Lessons Learnt
Why Frivol? ,[object Object]
I searched Thesaurus.com
Antonym of  save  or  put aside , actually ,[object Object]
Uses Redis which is  fast  and  persistent
Allows expiry of aging data
Great for caching

Más contenido relacionado

Similar a Frivolously simple temporary storage backed by Redis

Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshopjulien pauli
 
Creating Drupal A Module
Creating Drupal A ModuleCreating Drupal A Module
Creating Drupal A Modulearcaneadam
 
SynapseIndia drupal presentation on drupal best practices
SynapseIndia drupal  presentation on drupal best practicesSynapseIndia drupal  presentation on drupal best practices
SynapseIndia drupal presentation on drupal best practicesSynapseindiappsdevelopment
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Pythondn
 
Metaprogramming Rails
Metaprogramming RailsMetaprogramming Rails
Metaprogramming RailsJustus Eapen
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshopjulien pauli
 
The Ring programming language version 1.6 book - Part 76 of 189
The Ring programming language version 1.6 book - Part 76 of 189The Ring programming language version 1.6 book - Part 76 of 189
The Ring programming language version 1.6 book - Part 76 of 189Mahmoud Samir Fayed
 
How to improve problem solving skills
How to improve problem solving skillsHow to improve problem solving skills
How to improve problem solving skillsYun Yuan
 
Fast and Reproducible Deep Learning
Fast and Reproducible Deep LearningFast and Reproducible Deep Learning
Fast and Reproducible Deep LearningGreg Gandenberger
 
The Naked Bundle - Symfony Usergroup Belgium
The Naked Bundle - Symfony Usergroup BelgiumThe Naked Bundle - Symfony Usergroup Belgium
The Naked Bundle - Symfony Usergroup BelgiumMatthias Noback
 
Terraform training - Modules 🎒
Terraform training - Modules 🎒Terraform training - Modules 🎒
Terraform training - Modules 🎒StephaneBoghossian1
 
Pursuing Performance in Store
Pursuing Performance in StorePursuing Performance in Store
Pursuing Performance in StoreESUG
 
The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185Mahmoud Samir Fayed
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014Matthias Noback
 
The Drupal 7 Worst Practices Catalogue
The Drupal 7 Worst Practices CatalogueThe Drupal 7 Worst Practices Catalogue
The Drupal 7 Worst Practices CatalogueAlexandre Israël
 
Reproducibility with R
Reproducibility with RReproducibility with R
Reproducibility with RMartin Jung
 

Similar a Frivolously simple temporary storage backed by Redis (20)

Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshop
 
Creating Drupal A Module
Creating Drupal A ModuleCreating Drupal A Module
Creating Drupal A Module
 
SynapseIndia drupal presentation on drupal best practices
SynapseIndia drupal  presentation on drupal best practicesSynapseIndia drupal  presentation on drupal best practices
SynapseIndia drupal presentation on drupal best practices
 
Why Drupal is Rockstar?
Why Drupal is Rockstar?Why Drupal is Rockstar?
Why Drupal is Rockstar?
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
Metaprogramming Rails
Metaprogramming RailsMetaprogramming Rails
Metaprogramming Rails
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshop
 
The Ring programming language version 1.6 book - Part 76 of 189
The Ring programming language version 1.6 book - Part 76 of 189The Ring programming language version 1.6 book - Part 76 of 189
The Ring programming language version 1.6 book - Part 76 of 189
 
Andy On Closures
Andy On ClosuresAndy On Closures
Andy On Closures
 
How to improve problem solving skills
How to improve problem solving skillsHow to improve problem solving skills
How to improve problem solving skills
 
Django design-patterns
Django design-patternsDjango design-patterns
Django design-patterns
 
Fast and Reproducible Deep Learning
Fast and Reproducible Deep LearningFast and Reproducible Deep Learning
Fast and Reproducible Deep Learning
 
The Naked Bundle - Symfony Usergroup Belgium
The Naked Bundle - Symfony Usergroup BelgiumThe Naked Bundle - Symfony Usergroup Belgium
The Naked Bundle - Symfony Usergroup Belgium
 
Terraform training - Modules 🎒
Terraform training - Modules 🎒Terraform training - Modules 🎒
Terraform training - Modules 🎒
 
Module net cdf4
Module net cdf4 Module net cdf4
Module net cdf4
 
Pursuing Performance in Store
Pursuing Performance in StorePursuing Performance in Store
Pursuing Performance in Store
 
The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014
 
The Drupal 7 Worst Practices Catalogue
The Drupal 7 Worst Practices CatalogueThe Drupal 7 Worst Practices Catalogue
The Drupal 7 Worst Practices Catalogue
 
Reproducibility with R
Reproducibility with RReproducibility with R
Reproducibility with R
 

Frivolously simple temporary storage backed by Redis

  • 1.
  • 7.
  • 9.
  • 10. Uses Redis which is fast and persistent
  • 11. Allows expiry of aging data
  • 13.
  • 14. Set Frivol::Config.redis_config= in environment.rb
  • 15. include Frivol or Frivol::Config.include_in
  • 16. Simply use store and retrieve methods
  • 17. Stored keys are merged, not overwritten
  • 18. expire_storage and delete_storage
  • 19. Override storage_key if not using ActiveRecord
  • 20. Usage – Example from Mad Mimi # environment.rb # Each environment has a REDIS_CONFIG, eg. development.rb: # REDIS_CONFIG = { :host => &quot;localhost&quot;, :port => 6379 } Frivol::Config.redis_config = REDIS_CONFIG # Frivol could be included in all AR models using: # Frivol::Config.include_in ActiveRecord::Base, 10.minutes # audience_list.rb class AudienceList < ActiveRecord::Base include Frivol storage_expires_in 1.day has_many :memberships, :dependent => :destroy has_many :audience_members, :through => :memberships # ... def list_size retrieve :list_size => :force_list_size_update end def force_list_size_update new_size = audience_members.size store :list_size => new_size new_size end # ... end
  • 21.
  • 22. Uses Module#included (class methods)
  • 23.
  • 24. Resolves symbols vs strings for keys
  • 26. Implementation – Config & Included module Config def self.redis_config=(config) @@redis = Redis.new(config) end def self.redis @@redis end def self.include_in(host_class, storage_expires_in = nil) host_class.send(:include, Frivol) host_class.storage_expires_in storage_expires_in if storage_expires_in end end module ClassMethods def storage_expires_in(time) @frivol_storage_expiry = time end def storage_expiry @frivol_storage_expiry end end def self.included(host) host.extend(ClassMethods) end
  • 27. Implementation - Helpers module Helpers def self.store_hash(instance) hash = instance.instance_variable_get(:@frivol_hash) is_new = instance.instance_variable_get(:@frivol_is_new) key = instance.send(:storage_key) Frivol::Config.redis[key] = hash.to_json if is_new instance.expire_storage instance.class.storage_expiry instance.instance_variable_set :@frivol_is_new, false end end def self.retrieve_hash(instance) return instance.instance_variable_get(:@frivol_hash) => if instance.instance_variable_defined? :@frivol_hash key = instance.send(:storage_key) json = Frivol::Config.redis[key] instance.instance_variable_set :@frivol_is_new, json.nil? hash = json.nil? ? {} : JSON.parse(json) instance.instance_variable_set :@frivol_hash, hash hash end def self.delete_hash(instance) key = instance.send(:storage_key) Frivol::Config.redis.del key instance.instance_variable_set :@frivol_hash, {} end end
  • 28. Implementation – Instance Methods def store(keys_and_values) Frivol::Helpers.retrieve_hash self keys_and_values.each do |key, value| @frivol_hash[key.to_s] = value end Frivol::Helpers.store_hash self end def retrieve(keys_and_defaults) Frivol::Helpers.retrieve_hash self result = keys_and_defaults.map do |key, default| @frivol_hash[ key.to_s ] || ( default.is_a?(Symbol) && respond_to?(default) && => send(default) ) || default end return result.first if result.size == 1 result end def delete_storage Frivol::Helpers.delete_hash self end def expire_storage(time) return if time.nil? Frivol::Config.redis.expire storage_key, time end def storage_key @frivol_key ||= &quot;#{self.class.name}-#{id}&quot; end
  • 29.
  • 30.
  • 31.
  • 32. retrieve with a splat, instead of hash
  • 33.
  • 34.
  • 35. retrieve_default method to override class set default
  • 36.
  • 37.
  • 38.
  • 39. OpenOffice is pretty aweful for creating presentations (but it works)
  • 40.