RDS can be used together with ApsaraDB for Memcache and ApsaraDB for Redis to form a storage solution with high throughput and low delay. The following section describes the cached data persistence solution based on the combined use of RDS and ApsaraDB for Memcache.

Background information

Compared with the RDS, the RDS cache product has the following two features:

  • High response speed: The request delay of the RDS for Memcache and the RDS for Redis is usually within several milliseconds.

  • The cache area can support a higher QPS (Requests Per Second) than the RDS.

System requirements

  • Bmemcached (with support of SASL extension) has been installed in the local environment or ECS.

    Bmemcached download address: Click to download.

    The bmemcached installation command is as follows:

    pip install python-binary-memcached
  • Python is used as an example. Python and pip must be installed in the local environment or ECS.

Sample code

The following sample code realizes the combined use of RDS and ApsaraDB for Memcache:

/usr/bin/env python
import bmemcached
Memcache_client = bmemcached.Client((‘ip:port’), ‘user’, ‘passwd’)
#Search for a value in ApsaraDB for Memcache
res = os.client.get(‘test’)
if res is not None:
    return res #Return the searched value
else:
    #Query RDS if the value is not found
    res = mysql_client.fetchone(sql)
     Memcache_client.put(‘test’, res) #Write cached data to ApsaraDB for Memcache
    return res