// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package cache.mencached;

import net.spy.memcached.AddrUtil;
import net.spy.memcached.ConnectionFactoryBuilder;
import net.spy.memcached.ConnectionFactoryBuilder.Protocol;
import net.spy.memcached.MemcachedClient;

public class TestFunctional {
    private static void test(MemcachedClient cache) throws InterruptedException {
        // basic put, get and remove
        cache.set("v", 0, 123);
        System.out.println(cache.get("v"));
        cache.delete("v");
        System.out.println(cache.get("v"));
        cache.set("v", 0, 123);
        System.out.println(cache.get("v"));
        // persistence
        Integer counter = (Integer)cache.get("counter");
        if(counter == null) {
            counter = 0;
        }
        counter++;
        System.out.println(counter);
        cache.set("counter", 0, counter);
        // list all not supported
        // listener not supported
    }
    public static void main(String[] args) throws Exception {
        MemcachedClient cache = new MemcachedClient(new ConnectionFactoryBuilder().setProtocol(Protocol.BINARY).build(), AddrUtil.getAddresses("localhost:11211"));
        test(cache);
        cache.shutdown();
    }
}
