Return to Snippet

Revision: 64983
at October 11, 2013 20:42 by JulienLeloup


Initial Code
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)

Initial URL


Initial Description
Script called in CLI to insert a key/value pair in a local memcached (default installation, on port 11211).

Example :
python <script> -k key -v value

Note : this script will show some help with '-h' parameter.

Initial Title
Insert key/value pair in memcached

Initial Tags


Initial Language
Python