hi,all:
In python, we can define a dct={'name':'jia','age':20} and get name-value
via dct.get('name')
if in dct, key is not exists, we can get a default value via :
dct.get('weight',100)
okay, now i want to know in memcached, how to get a default value when the
key is not available or memcached is shutdown?
>>> import memcache
>>> mc = memcache.Client(['127.0.0.1:11211'], debug=0)
>>> mc.get('sim:15242410793bid:8182785')
31
>>> a = mc.get('sim:15242410793bid:8182789')
>>> repr(a)
'None'
>>> a-10
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
i try to get a default value as follows, failed:
>>> a = mc.get('sim:15242410793bid:8182789',0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: get() takes exactly 2 arguments (3 given)
in short, how to provide a default value when key-value is not found?
any response will be welcome!
--Jia Xiaolei