1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | package com.dsyjs.helper; import java.util.Iterator; import com.meetup.memcached.*; public class MemcachedHelper { public static void main(String[] args) { String[] servers = { "127.0.0.1:11211" }; SockIOPool pool = SockIOPool.getInstance(); pool.setServers( servers ); pool.setFailover( true ); pool.setInitConn( 10 ); pool.setMinConn( 5 ); pool.setMaxConn( 250 ); pool.setMaintSleep( 30 ); pool.setNagle( false ); pool.setSocketTO( 3000 ); pool.setAliveCheck( true ); pool.initialize(); MemcachedClient mcc = new MemcachedClient(); Iterator it=mcc.stats().keySet().iterator(); while (it.hasNext()) { System.out.println(mcc.stats().get( "127.0.0.1:11211" )); System.out.println(it.next()); } Iterator its=mcc.statsSlabs().keySet().iterator(); while (its.hasNext()) { System.out.println(mcc.get( "" +its.next())); } for ( int i = 0 ; i < 10 ; i++ ) { boolean success = mcc.set( "" + i, "Hello!" ); String result = (String)mcc.get( "" + i ); System.out.println( String.format( "set( %d ): %s" , i, success ) ); System.out.println( String.format( "get( %d ): %s" , i, result ) ); } System.out.println( "\n\t -- sleeping --\n" ); try { Thread.sleep( 10000 ); } catch ( Exception ex ) { } for ( int i = 0 ; i < 10 ; i++ ) { boolean success = mcc.set( "x" + i, "Hello!" ); String result = (String)mcc.get( "" + i ); System.out.println( String.format( "set( %d ): %s" , i, success ) ); System.out.println( String.format( "get( %d ): %s" , i, result ) ); } } } |