如何构建Memcached Docker容器(2)

` # Import python-memcache and sys for arguments
 import memcache
 import sys
 
 # Set address to access the Memcached instance
 addr = 'localhost'
 
 # Get number of arguments
 # Expected format: python cache.py [memcached port] [key] [value]
 len_argv = len(sys.argv)
 
 # At least the port number and a key must be supplied
 if len_argv < 3:
    sys.exit("Not enough arguments.")
 
 # Port is supplied and a key is supplied - let's connect!
 port  = sys.argv[1]
 cache = memcache.Client(["{0}:{1}".format(addr, port)])
 
 # Get the key
 key  = str(sys.argv[2])
 
 # If a value is also supplied, set the key-value pair
 if len_argv == 4:

value = str(sys.argv[3])
    cache.set(key, value)
 
    print "Value for {0} set!".format(key)
 
 # If a value is not supplied, return the value for the key
 else:
 
    value = cache.get(key)
 
    print "Value for {0} is {1}.".format(key, value)`
 

测试Docker的Memcached实例:
   
  # Example: python cache.py [port] [key] [value]
 python cache.py 45001 my_test_key test_value
 
 # Return: Value for my_test_key set
 
 # See if the key is set:
 python cache.py 45001 my_test_key
 
 # Return: Value for my_test_key is test_value.

更多Docker相关教程见以下内容

Docker安装应用(CentOS 6.5_x64)  

Ubuntu 14.04安装Docker   

Ubuntu使用VNC运行基于Docker的桌面系统 

阿里云CentOS 6.5 模板上安装 Docker  

Ubuntu 15.04下安装Docker   

在Ubuntu Trusty 14.04 (LTS) (64-bit)安装Docker  

在 Ubuntu 15.04 上如何安装Docker及基本用法

Docker 的详细介绍请点这里
Docker 的下载地址请点这里

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/1e521dfc1c1313c63030e2587e1fc58f.html