Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

redis backed memoization helpers

tree: 9cdfcab311

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 script
Octocat-spinner-32 test
Octocat-spinner-32 vendor
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
README.rdoc

memodis

semi-transparent memoization; backed by redis;

writes are sent to the master, reads are sent to an approriate slave.

Two features:

  1. Memodis#memoize

  2. Memodis::DistCache

Example

def fib(num)
  return num if num < 2
  fib(num - 1) + fib(num - 2)
end

puts "Before memoize: "
puts fib(33) => 3524578 # after ~ 7 seconds

extend Memodis
memoize :fib, Memodis::DistCache.new({
  :key_gen => lambda { |k| "fib(#{k})" },
  :decoder => :integer,
  :expires => (10 * 60),
  :master  => '127.0.0.1:16379 127.0.0.1:16380'.split,
  :slaves  => '127.0.0.1:16389 127.0.0.1:16390 
               127.0.0.1:16391 127.0.0.1:16392
               127.0.0.1:16393 127.0.0.1:16394'.split
})

puts "After memoize: "
puts fib(33) => 3524578 # after ~ 0.03   seconds
puts fib(33) => 3524578 # after ~ 0.0001 seconds
puts fib(33) => 3524578 # after ~ 0.0001 seconds

Background

  1. blog.grayproductions.net/articles/caching_and_memoization

  2. code.google.com/p/redis & github.com/ezmobius/redis-rb

Important Moving Parts

  1. code.google.com/p/redis/wiki/GetCommand

  2. code.google.com/p/redis/wiki/SetCommand

  3. code.google.com/p/redis/wiki/SetnxCommand

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 levicook@gmail.com. See LICENSE for details.

Something went wrong with that request. Please try again.