/[projects]/misc/memcached/JavaConsumer/Consumer.java
ViewVC logotype

Contents of /misc/memcached/JavaConsumer/Consumer.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 644 - (show annotations) (download)
Fri Apr 9 22:02:22 2010 UTC (14 years, 1 month ago) by torben
File size: 627 byte(s)
Added memcached producer/consumer example
1 import net.spy.memcached.MemcachedClient;
2 import java.net.InetSocketAddress;
3
4 public class Consumer
5 {
6 static final int SLOT_COUNT = 10;
7
8 public static void main(String args[]) throws Exception
9 {
10 MemcachedClient c = new MemcachedClient( new InetSocketAddress("localhost", 11211) );
11
12 int current = 0;
13 while (true) {
14
15 String key = "slot:" + current;
16
17
18 String data = (String) c.get(key);
19 if ( data != null) {
20 System.out.println("Consuming slot " + current);
21
22 System.out.println("Got >" +data + "<");
23
24 c.delete(key);
25 }
26
27
28 current = (current+1) % SLOT_COUNT;
29
30 Thread.sleep( 900 );
31 }
32 }
33 }

  ViewVC Help
Powered by ViewVC 1.1.20