Skip to content

Instantly share code, notes, and snippets.

@egbertp
Last active September 20, 2015 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egbertp/98b06b78265a1bbdc2ae to your computer and use it in GitHub Desktop.
Save egbertp/98b06b78265a1bbdc2ae to your computer and use it in GitHub Desktop.
Service file memcached.rb that communicates with the memcached servers defined in ENV["MEMCACHED_SERVERS"]
# Add to your Gemfile: gem 'activesupport', :require => false
require 'active_support/inflector'
class Memcached
extend ::ActiveSupport::Inflector # Needed for .parameterize
def initialize
# [Egbert Pot - 2015-09-20 14:23:02]
# e.g.: export MEMCACHED_NAMESPACE=feed-supplier
# e.g.: deis config:set MEMCACHED_NAMESPACE=feed-supplier
unless ENV["MEMCACHED_NAMESPACE"].nil? || ENV["MEMCACHED_NAMESPACE"].delete(' ').empty?
options = { :namespace => ENV["MEMCACHED_NAMESPACE"].parameterize }
end
options ||= { :namespace => 'empty' }
# [Egbert Pot - 2015-09-20 14:23:02]
# e.g.: export MEMCACHED_SERVERS=10.133.50.100:11211,10.133.50.101:11211,10.133.50.102:11211
# e.g.: deis config:set MEMCACHED_SERVERS=10.133.50.100:11211,10.133.50.101:11211,10.133.50.102:11211
unless ENV["MEMCACHED_SERVERS"].nil? || ENV["MEMCACHED_SERVERS"].delete(' ').empty?
memcached_servers = ENV["MEMCACHED_SERVERS"].split(',')
end
memcached_servers ||= 'localhost:11211'
@dc = Dalli::Client.new(memcached_servers, options)
end
def ins_data
@dc.set('abc', 123)
end
def get_data
value = @dc.get('abc')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment