C C PHP Java Python Ruby Perl NET



Использование � Реализации клиентских библиотек для многих языков программирования (C / C++, PHP, Java, Python, Ruby, Perl, . NET, My. SQL, Postgre. SQL, Erlang, Lua, и др. ) � Используется в: You. Tube Live. Journal, Wikipedia/Wikimedia, Amazon. com, Wikia, Source. Forge, Metacafe, Facebook, Twitter, Fotolog, The Pirate Bay etc.







![Команды сохранения значения <command name> <key> <flags> <exptime> <bytes> [noreply]rn cas <key> <flags> <exptime> Команды сохранения значения <command name> <key> <flags> <exptime> <bytes> [noreply]rn cas <key> <flags> <exptime>](http://slidetodoc.com/presentation_image_h2/dc78c582e22d6145184d720cb57f5b5a/image-11.jpg)
Команды сохранения значения <command name> <key> <flags> <exptime> <bytes> [noreply]rn cas <key> <flags> <exptime> <bytes> <cas unqiue> [noreply]rn <command name> = set / add / replace / append / prepend / cas (check and set)


Библиотека spymemcached � Memcached. Client � � // c=new Memcached. Client( new Inet. Socket. Address("hostname", port. Num)); Store a value (async) for one hour � c. set("some. Key", 3600, some. Object); � // Retrieve a value (synchronously). � Object my. Object=c. get("some. Key");

Библиотека spymemcached � � � � // Get a memcached client connected to several servers Memcached. Client c=new Memcached. Client( Addr. Util. get. Addresses("server 1: 11211 server 2: 11211")); // Try to get a value, for up to 5 seconds, and cancel if it doesn't return Object my. Obj=null; Future<Object> f=c. async. Get("some. Key"); try { my. Obj=f. get(5, Time. Unit. SECONDS); } catch(Timeout. Exception e) { // Since we don't need this, go ahead and cancel the operation. This // is not strictly necessary, but it'll save some work on the server. f. cancel(false); // Do other timeout related stuff }

Библиотека spymemcached � get � public Object get(String key)Get with a single key and decode using the default transcoder. � Specified by: get in interface Memcached. Client. IFParameters: key - the key to get. Returns: the result from the cache (null if there is none)Throws: Operation. Timeout. Exception if the global operation timeout is exceeded. Illegal. State. Exception - in the rare circumstance where queue is too full to accept any more requests

Библиотека spymemcached � async. Get � public Future<Object> async. Get(String key)Get the given key asynchronously and decode with the default transcoder. � Specified by: async. Get in interface Memcached. Client. IFParameters: key - the key to fetch. Returns: a future that will hold the return value of the fetch. Throws: Illegal. State. Exception - in the rare circumstance where queue is too full to accept any more requests

Простой пример использования spymemcached package use_memcached; import net. spy. memcached. *; import java. net. *; public class Use_memcached { public static void main(String[] args) { try{ Memcached. Client c=new Memcached. Client(new Inet. Socket. Address("127. 0. 0. 1", 11211)); c. set("key. A", 3600, "value. A"); c. set("key. B", 3600, "value. B"); c. set("key. C", 3600, "value. C");

Простой пример использования spymemcached Object my. Object=c. get("key. A"); System. out. println("my. Object = "+my. Object); } catch (Exception e) { System. out. println(e. to. String()+" "+e. get. Message()); } } } run: my. Object = value. A

Проверка через telnet alex@HP 620: ~$ telnet 127. 0. 0. 1 11211 Trying 127. 0. 0. 1. . . Connected to 127. 0. 0. 1. Escape character is '^]'. get key. A VALUE key. A 0 6 value. A END get key. B VALUE key. B 0 6 value. B END get key. C VALUE key. C 0 6 value. C END

Проверка через telnet gets key. A VALUE key. A 0 6 6 value. A END gets key. B VALUE key. B 0 6 7 value. B END gets key. C VALUE key. C 0 6 8 value. C END

Статистика stats STAT pid 9839 STAT uptime 13649 STAT time 1330122057 STAT version 1. 4. 2 STAT pointer_size 32 STAT rusage_user 0. 232014 STAT rusage_system 0. 128008 STAT curr_connections 11 STAT total_connections 13 STAT connection_structures 12 STAT cmd_get 19 STAT cmd_set 9 STAT cmd_flush 0 STAT get_hits 19 STAT get_misses 8 STAT delete_misses 0 STAT delete_hits 0 STAT incr_misses 0 STAT incr_hits 0 STAT decr_misses 0 STAT decr_hits 0 STAT cas_misses 1 STAT cas_hits 0 STAT cas_badval 0 STAT bytes_read 609 STAT bytes_written 764 STAT limit_maxbytes 67108864 STAT accepting_conns 1 STAT listen_disabled_num 0 STAT threads 4 STAT conn_yields 0 STAT bytes 177 STAT curr_items 3 STAT total_items 8 STAT evictions 0 END
- Slides: 21