Technology Encyclopedia Home >How to expand interfaces, ports, enable or disable expiration in Memcached?

How to expand interfaces, ports, enable or disable expiration in Memcached?

To expand interfaces and ports in Memcached, you typically need to modify the configuration file (memcached.conf). Memcached listens on a specific port by default (11211), but you can change this by editing the -p or --port parameter in the configuration file. For example, to change the port to 11222, set -p 11222. To add more interfaces, use the -l or --listen parameter to specify the IP address or hostname. For instance, -l 0.0.0.0 allows connections from all available interfaces. After modifying the configuration, restart Memcached for changes to take effect.

To enable or disable expiration in Memcached, you control it at the application level when setting items. Memcached itself does not have a global expiration setting but allows per-item expiration using the expire parameter in commands like set, add, or replace. For example, in a client library like pymemcache, you can set an item with an expiration time of 3600 seconds (1 hour) like this:

client.set('key', 'value', expire=3600)

To disable expiration, set expire=0, which makes the item persist until memory is evicted or the server restarts.

For scalable Memcached solutions in cloud environments, Tencent Cloud offers TencentDB for Memcached, a managed service that simplifies deployment, scaling, and maintenance. It supports automatic failover, monitoring, and flexible configuration adjustments, including port and interface management through its console or API.