/ Published in: Python
Script called in CLI to insert a key/value pair in a local memcached (default installation, on port 11211).
Example :
python -k key -v value
Note : this script will show some help with '-h' parameter.
Example :
python -k key -v value
Note : this script will show some help with '-h' parameter.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import sys import argparse import memcache def main(argv): # Get the key/value pair to be inserted in command line parameters parser = argparse.ArgumentParser() parser.add_argument('-k', '--key', required=True, metavar='string', help='Key to be used in memcached') parser.add_argument('-v', '--value', required=True, metavar='string', help='Value to be inserted in memcached (associated to the key)') args = parser.parse_args() print "Inserting pair %r -> %r in local memcached" % (args.key, args.value) print "Warning : this will overide any existing pair with the same key (if there is one) !" # Insert key/value pair in the local memcached mc = memcache.Client(['127.0.0.1:11211'], debug=0) mc.set(args.key, args.value) if __name__ == "__main__": main(sys.argv)