Skip to content

Instantly share code, notes, and snippets.

@otype
Created June 28, 2009 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save otype/137347 to your computer and use it in GitHub Desktop.
Save otype/137347 to your computer and use it in GitHub Desktop.
Memcached in Ruby
require 'rubygems'
require 'memcache'
class Memcaching
def initialize
@cache = MemCache.new 'localhost:11211', :namespace => 'goofingaroundwithmemcached'
end
def load_key_into_memcache(key,value)
@cache.set(key, value, 0)
end
def key_from_memcache(key)
@cache.get(key)
end
end
mc = Memcaching.new
key = "mykey"
value = "myvalue"
mc.load_key_into_memcache(key,value)
puts mc.key_from_memcache(key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment