ValueError: gets without cas behavior in pylibmc

227 Views Asked by At

I'm trying to use the gets and cas methods from pylibmc(v1.5.2) to interact with the memcached server. As documented, we should pass the cas token from gets to cas.

token = mc.gets("key_python_1")
mc.cas("key_python_1", "value_python_1_new", token)

# Or
mc.cas("key_python_1", "value_python_1_new", mc.gets("key_python_1"))

However, I got a ValueError: gets without cas behavior err which is hard to understand.

Could someone shed some light on this issue? Any working example will be appreciated. Thanks ;)

--- Update ---

This is how I get mc.

import pylibmc

mc = pylibmc.Client(["127.0.0.1"], binary=True, behaviors={"tcp_nodelay": True, "ketama": True})
1

There are 1 best solutions below

0
AllenT On

To fix this, you just need to add "cas": True to the list of behaviors.

import pylibmc

mc = pylibmc.Client(["127.0.0.1"], binary=True, behaviors={"cas": True, "tcp_nodelay": True, "ketama": True})