Cached data persistence

Last Updated: Dec 07, 2017

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:

    1. 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:

  1. #!/usr/bin/env python
  2. import bmemcached
  3. Memcache_client = bmemcached.Client((‘ip:port’), user’, passwd’)
  4. #Search for a value in ApsaraDB for Memcache
  5. res = os.client.get(‘test’)
  6. if res is not None:
  7. return res #Return the searched value
  8. else:
  9. #Query RDS if the value is not found
  10. res = mysql_client.fetchone(sql)
  11. Memcache_client.put(‘test’, res) #Write cached data to ApsaraDB for Memcache
  12. return res
Thank you! We've received your feedback.