Skip to content

Commit

Permalink
[ISPN-300] (Demo memcached being accessed from a non-Java client) Add…
Browse files Browse the repository at this point in the history
…ed python script that talks to memcached. It's working with Infinispan memcached impl :)
  • Loading branch information
galderz committed Jan 22, 2010
1 parent 21d4210 commit cc3673f
Showing 1 changed file with 73 additions and 0 deletions.
@@ -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

0 comments on commit cc3673f

Please sign in to comment.