[infinispan-commits] Infinispan SVN: r1427 - trunk/server/memcached/src/main/resources.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Fri Jan 29 10:38:18 EST 2010
Author: galder.zamarreno at jboss.com
Date: 2010-01-29 10:38:18 -0500 (Fri, 29 Jan 2010)
New Revision: 1427
Added:
trunk/server/memcached/src/main/resources/sample_python_memcached_reader.py
trunk/server/memcached/src/main/resources/sample_python_memcached_writer.py
Modified:
trunk/server/memcached/src/main/resources/sample_python_memcached_client.py
Log:
[ISPN-300] (Demo memcached being accessed from a non-Java client) Improve client and reader/writer scripts.
Modified: trunk/server/memcached/src/main/resources/sample_python_memcached_client.py
===================================================================
--- trunk/server/memcached/src/main/resources/sample_python_memcached_client.py 2010-01-29 13:36:27 UTC (rev 1426)
+++ trunk/server/memcached/src/main/resources/sample_python_memcached_client.py 2010-01-29 15:38:18 UTC (rev 1427)
@@ -7,67 +7,61 @@
import memcache
import time
-from ftplib import print_line
mc = memcache.Client(['127.0.0.1:11211'], debug=0)
+def setAndGet(mc, k, v):
+ mc.set(k, v)
+ get(mc, k, v)
+
+def get(mc, k, v):
+ value = mc.get(k)
+ if value == v:
+ print "OK"
+ else:
+ print "FAIL"
+
+def setAndGetNone(mc, k, v, t):
+ mc.set(k, v, t)
+ time.sleep(t + 2)
+ value = mc.get(k)
+ if value == None:
+ print "OK"
+ else:
+ print "FAIL"
+
+def delete(mc, k):
+ ret = mc.delete(k)
+ if ret != 0:
+ print "OK"
+ else:
+ print "FAIL"
+
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"
+setAndGet(mc, "Simple_Key", "Simple value")
print "Testing delete ['{0}'] ...".format("Simple_Key"),
-value = mc.delete("Simple_Key")
-if value != 0:
- print "OK"
-else:
- print "FAIL"
+delete(mc, "Simple_Key")
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"
+setAndGetNone(mc, "Expiring_Key", 999, 3)
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"
+get(mc, "Incr_Decr_Key", "4")
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"
+get(mc, "Incr_Decr_Key", "3")
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"
+get(mc, "Incr_Decr_Key", "1")
print "Finally, delete ['{0}'] ...".format("Incr_Decr_Key"),
-value = mc.delete("Incr_Decr_Key")
-if value != 0:
- print "OK"
-else:
- print "FAIL"
+delete(mc, "Incr_Decr_Key")
-
## For more information see http://community.jboss.org/wiki/UsingInfinispanMemcachedServer
\ No newline at end of file
Added: trunk/server/memcached/src/main/resources/sample_python_memcached_reader.py
===================================================================
--- trunk/server/memcached/src/main/resources/sample_python_memcached_reader.py (rev 0)
+++ trunk/server/memcached/src/main/resources/sample_python_memcached_reader.py 2010-01-29 15:38:18 UTC (rev 1427)
@@ -0,0 +1,75 @@
+#!/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 ['{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 ['{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_Key", "1"),
+mc.set("Incr_Key", "1") # note that the key used for incr/decr must be a string.
+mc.incr("Incr_Key")
+mc.incr("Incr_Key")
+mc.incr("Incr_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("Decr_Key", "4"),
+mc.set("Decr_Key", "4")
+mc.decr("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("Multi_Decr_Key", "3"),
+mc.set("Multi_Decr_Key", "3")
+mc.decr("Multi_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
Added: trunk/server/memcached/src/main/resources/sample_python_memcached_writer.py
===================================================================
--- trunk/server/memcached/src/main/resources/sample_python_memcached_writer.py (rev 0)
+++ trunk/server/memcached/src/main/resources/sample_python_memcached_writer.py 2010-01-29 15:38:18 UTC (rev 1427)
@@ -0,0 +1,89 @@
+#!/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)
+
+def set(mc, key, val, time = 0):
+ ret = mc.set(key, val, time)
+ if ret != 0:
+ print "OK"
+ else:
+ print "FAIL: returned {0}".format(ret)
+
+def incr(mc, expected, key, delta = 1):
+ ret = mc.incr(key)
+ if ret == expected:
+ print "OK"
+ else:
+ print "FAIL: returned {0}".format(ret)
+
+def decr(mc, expected, key, delta = 1):
+ ret = mc.decr(key)
+ if ret == expected:
+ print "OK"
+ else:
+ print "FAIL: returned {0}".format(ret)
+
+print "Testing set ['{0}': {1}] ...".format("Simple_Key", "Simple value"),
+set(mc, "Simple_Key", "Simple value")
+#ret = mc.set("Simple_Key", "Simple value")
+#if ret != 0:
+# print "OK"
+#else:
+# print "FAIL"
+
+print "Testing set ['{0}' : {1} : {2}] ...".format("Expiring_Key", 999, 3),
+set(mc, "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_Key", "1"),
+set(mc, "Incr_Key", "1") # note that the key used for incr/decr must be a string.
+incr(mc, 2, "Incr_Key")
+incr(mc, 3, "Incr_Key")
+incr(mc, 4, "Incr_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("Decr_Key", "4"),
+set(mc, "Decr_Key", "4")
+decr(mc, 3, "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("Multi_Decr_Key", "3"),
+set(mc, "Multi_Decr_Key", "3")
+decr(mc, 1, "Multi_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