4
Memcached Cloud is a fully-managed service for running your Memcached in a reliable and fail-safe manner. Your dataset is constantly replicated, so if a node fails, an auto-switchover mechanism guarantees data is served without interruption. Memcached Cloud provides various data persistence options as well as remote backups for disaster recovery purposes. You can quickly and easily get your apps up and running with Memcached Cloud through its add-on for Codename: BlueMix, just tell us how much memory you need and get started instantly with your first Memcached bucket. A Memcached bucket is created in seconds and from that moment on, all operations are fully-automated. The service completely frees developers from dealing with nodes, clusters, server lists, scaling and failure recovery, while guaranteeing absolutely no data loss. Creating A Memcached Cloud Service You can use the Codename: BlueMix web user interface or the cf command line interface to create an instance of the Memcached Cloud service. The following cf command creates the service instance: $ cf create-service memcachedcloud PLAN SERVICE_INSTANCE where PLAN is the desired plan (e.g. the free 25mb plan) and SERVICE_INSTANCE is the name of the service instance. Binding Your Memcached Cloud Service Use the web user interface or the command line interface to bind a Memcached Cloud service instance to an application. When using cf , the following command binds the instance to the application: $ cf bind-service APP SERVICE_INSTANCE where APP is the name of the application and SERVICE_INSTANCE is the name of the service instance. Once your Memcached Cloud service is bound to your app, the service credentials will be stored in the VCAP_SERVICES environment variable in the following format: { "memcachedcloud-null": [ { "name": "dev-session-cache", "label": "memcachedcloud-null", "plan": "25mb", "credentials": { "username": "...", "servers": "pub-memcached-11211.dal-05.1.sl.redislabs.com:11211", "password": "..." } } ] } Ruby Rails Sinatra Java Using Memcached with Ruby Dalli is a high performance pure Ruby client for accessing memcached servers, which uses the binary protocol. For usage with Rails 3.x, update the Gemfile: gem 'dalli'

Memcached Cloud on IBM Codename: BlueMix - Manual

Embed Size (px)

DESCRIPTION

This document contains instructions on how to use Memcached Cloud from Redis Labs on IBM's Codename: BlueMix

Citation preview

  • Memcached Cloud is a fully-managed service for running your Memcached in areliable and fail-safe manner. Your dataset is constantly replicated, so if a nodefails, an auto-switchover mechanism guarantees data is served withoutinterruption. Memcached Cloud provides various data persistence options as wellas remote backups for disaster recovery purposes. You can quickly and easily getyour apps up and running with Memcached Cloud through its add-on forCodename: BlueMix, just tell us how much memory you need and get startedinstantly with your first Memcached bucket.

    A Memcached bucket is created in seconds and from that moment on, alloperations are fully-automated. The service completely frees developers fromdealing with nodes, clusters, server lists, scaling and failure recovery, whileguaranteeing absolutely no data loss.

    Creating A Memcached Cloud ServiceYou can use the Codename: BlueMix web user interface or the cf command lineinterface to create an instance of the Memcached Cloud service. The following cfcommand creates the service instance:

    $ cf create-service memcachedcloud PLAN SERVICE_INSTANCE

    where PLAN is the desired plan (e.g. the free 25mb plan) and SERVICE_INSTANCE isthe name of the service instance.

    Binding Your Memcached CloudServiceUse the web user interface or the command line interface to bind a MemcachedCloud service instance to an application. When using cf , the following commandbinds the instance to the application:

    $ cf bind-service APP SERVICE_INSTANCE

    where APP is the name of the application and SERVICE_INSTANCE is the name of theservice instance.

    Once your Memcached Cloud service is bound to your app, the service credentialswill be stored in the VCAP_SERVICES environment variable in the following format:

    { "memcachedcloud-null": [ { "name": "dev-session-cache", "label": "memcachedcloud-null", "plan": "25mb", "credentials": { "username": "...", "servers": "pub-memcached-11211.dal-05.1.sl.redislabs.com:11211", "password": "..." } } ]}

    RubyRailsSinatraJava

    Using Memcached with RubyDalli is a high performance pure Ruby client for accessing memcached servers,which uses the binary protocol.

    For usage with Rails 3.x, update the Gemfile:

    gem 'dalli'

  • And then install the gem via Bundler:

    bundle install

    Parse your credentials as follows:

    memcachedcloud_service = JSON.parse(ENV['VCAP_SERVICES'])["memcachedcloud-n/a"]credentials = memcachedcloud_service.first["credentials"]

    Lastly, in your config/environments/production.rb :

    config.cache_store = :dalli_store, credentials.servers, { :username => credentials.username, :password => credentials.password }

    Configuring Memcached on SinatraAdd this code snippet to your configure block:

    configure do . . . require 'dalli' memcachedcloud_service = JSON.parse(ENV['VCAP_SERVICES'])["memcachedcloud-n/a"] credentials = memcachedcloud_service.first["credentials"] $cache = Dalli::Client.new(credentials.servers.split(','), :username => credentials.username, :password => credentials.password) . . .end

    Testing from Ruby$cache.set("foo", "bar") # => true $cache.get("foo")# => "bar"

    Using Memcached with Javaspymemcached is a simple, asynchronous, single-threaded memcached clientwritten in Java. You can download the latest build from:https://code.google.com/p/spymemcached/downloads/list.

    To use the maven repository, start by specifying the repository:

    spy Spy Repository default http://files.couchbase.com/maven2/ false

    And specify the actual artifact as follows:

    spy spymemcached 2.8.9 provided

    Configure the connection to your Memcached Cloud service using theVCAP_SERVICES environment variable and the following code snippet:

    try {

  • String vcap_services = System.getenv("VCAP_SERVICES"); if (vcap_services != null && vcap_services.length() > 0) { // parsing memcachedcloud credentials JsonRootNode root = new JdomParser().parse(vcap_services); JsonNode "memcachedcloudNode = root.getNode("memcachedcloud-n/a"); JsonNode credentials = "memcachedcloudNode.getNode(0).getNode("credentials");

    // building the memcached client AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" }, new PlainCallbackHandler(credentials.getStringValue("username"), credentials.getStringValue("password")));

    MemcachedClient mc = new MemcachedClient( new ConnectionFactoryBuilder() .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setAuthDescriptor(ad).build(), AddrUtil.getAddresses(credentials.getStringValue("servers")));

    } } catch (InvalidSyntaxException ex) { // vcap_services could not be parsed.} catch (IOException ex) { // the memcached client could not be initialized. }

    Testing from Javamc.set("foo", 0, "bar");Object value = mc.get("foo");

    DashboardOur dashboard presents all performance and usage metrics of your MemcachedCloud service on a single screen, as shown below:

    To access your Memcached Cloud dashboard, click the service instance in yourCode Name: BlueMix console and then the LAUNCH MEMCACHEDCLOUDDASHBOARD button.

  • When using the Memcached Cloud console, you can then find the dashboard usingthe MY RESOURCES->Dashboard menu item.

    SupportAny Memcached Cloud support issues or product feedbacks are welcome via emailat [email protected] or from the services console under the SUPPORT->Helpdesk menu item.

    Additional resourcesDevelopers ResourcesMemcached Wiki

    Creating A Memcached Cloud ServiceBinding Your Memcached Cloud ServiceUsing Memcached with RubyConfiguring Memcached on SinatraTesting from Ruby

    Using Memcached with JavaTesting from Java

    DashboardSupportAdditional resources