Memcached : Use on Python2022/07/14 |
This is the example to use Memcached on Python.
|
|
[1] | Install Python Memcached Client Library. |
# install from EPEL [root@dlp ~]# dnf --enablerepo=epel -y install python3-memcached
|
[2] | This is the Basic usage on Python. |
[cent@dlp ~]$
vi use_memcache.py import memcache client = memcache.Client(["127.0.0.1:11211"], cache_cas=True) # set and get a Key client.set("key01", "value01") print("key01.value :", client.get("key01")) # append and get a Key client.append("key01", ",value02") print("key01.value :", client.get("key01")) client.set("key02", 1) # increment client.incr("key02", 100) print("key02.value :", client.get("key02")) # decrement client.decr("key02", 51) print("key02.value :", client.get("key02")) # CAS client.set("key03", "value03") print("key03.value :", client.gets("key03")) client.cas("key03", "value04") print("key03.value :", client.gets("key03")) # run [cent@dlp ~]$ python3 use_memcache.py key01.value : value01 key01.value : value01,value02 key02.value : 101 key02.value : 50 key03.value : value03 key03.value : value04 |
Sponsored Link |