Memcached : Use on Python2024/09/16 |
This is the example to use Memcached on Python. |
|
[1] | Install Python Memcached Client Library. |
root@dlp:~ # pkg install -y py311-python-memcached
|
[2] | This is the Basic usage on Python. |
freebsd@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 freebsd@dlp:~ $ python3.11 use_memcache.py key01.value : value01 key01.value : value01,value02 key02.value : 101 key02.value : 50 key03.value : value03 key03.value : value04 |
Sponsored Link |