[infinispan-commits] Infinispan SVN: r1410 - trunk/server/memcached/src/main/resources.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Fri Jan 22 12:26:02 EST 2010


Author: galder.zamarreno at jboss.com
Date: 2010-01-22 12:26:01 -0500 (Fri, 22 Jan 2010)
New Revision: 1410

Added:
   trunk/server/memcached/src/main/resources/sample_python_memcached_client.py
Log:
[ISPN-300] (Demo memcached being accessed from a non-Java client) Added python script that talks to memcached. It's working with Infinispan memcached impl :)

Added: trunk/server/memcached/src/main/resources/sample_python_memcached_client.py
===================================================================
--- trunk/server/memcached/src/main/resources/sample_python_memcached_client.py	                        (rev 0)
+++ trunk/server/memcached/src/main/resources/sample_python_memcached_client.py	2010-01-22 17:26:01 UTC (rev 1410)
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+
+#
+# Sample python code using the standard memcached library to talk to Infinispan memcached server
+# To use it, make sure you install Python memcached client library
+# 
+
+import memcache
+import time
+from ftplib import print_line
+
+mc = memcache.Client(['127.0.0.1:11211'], debug=0)
+
+print "Testing set/get ['{0}': {1}] ...".format("Simple_Key", "Simple value"),
+mc.set("Simple_Key", "Simple value")
+value = mc.get("Simple_Key")
+if value == "Simple value":
+   print "OK"
+else:
+   print "FAIL"
+
+print "Testing delete ['{0}'] ...".format("Simple_Key"),
+value = mc.delete("Simple_Key")
+if value != 0:
+   print "OK"
+else:
+   print "FAIL"
+
+print "Testing set/get ['{0}' : {1} : {2}] ...".format("Expiring_Key", 999, 3),
+mc.set("Expiring_Key", 999, 3)
+time.sleep(5)
+value = mc.get("Expiring_Key")
+if value == None:
+   print "OK"
+else:
+   print "FAIL"
+
+print "Testing increment 3 times ['{0}' : starting at {1} ] ...".format("Incr_Decr_Key", "1"),
+mc.set("Incr_Decr_Key", "1")   # note that the key used for incr/decr must be a string.
+mc.incr("Incr_Decr_Key")
+mc.incr("Incr_Decr_Key")
+mc.incr("Incr_Decr_Key")
+value = mc.get("Incr_Decr_Key")
+if value == "4":
+   print "OK"
+else:
+   print "FAIL"
+
+print "Testing decrement 1 time ['{0}' : starting at {1} ] ...".format("Incr_Decr_Key", "4"),
+mc.decr("Incr_Decr_Key")
+value = mc.get("Incr_Decr_Key")
+if value == "3":
+   print "OK"
+else:
+   print "FAIL"
+
+print "Testing decrement 2 times in one call ['{0}' : {1} ] ...".format("Incr_Decr_Key", "3"),
+mc.decr("Incr_Decr_Key", 2)
+value = mc.get("Incr_Decr_Key")
+if value == "1":
+   print "OK"
+else:
+   print "FAIL"
+
+print "Finally, delete ['{0}'] ...".format("Incr_Decr_Key"),
+value = mc.delete("Incr_Decr_Key")
+if value != 0:
+   print "OK"
+else:
+   print "FAIL"
+
+
+## For more information see http://community.jboss.org/wiki/UsingInfinispanMemcachedServer
\ No newline at end of file



More information about the infinispan-commits mailing list