pinterest / pymemcache

A comprehensive, fast, pure-Python memcached client.
https://pymemcache.readthedocs.io/
Apache License 2.0
768 stars 177 forks source link

Unable to flush memcache using flush_all() #357

Closed rikeshpatel14 closed 2 years ago

rikeshpatel14 commented 2 years ago

Sample code

import json
from pymemcache.client.base import Client

client = Client('######:7642')

msg = {"a":"b", "c":"d"}

client.set(key='key', value=json.dumps(msg), expire=0, noreply=False)
result = client.get(key='key', default=None)
print(json.loads(result))

client.flush_all(delay=0, noreply=False)
client.close()

Am trying to run the above code to add some dummy key-value data to memcache, and finally flush it, but the _client.flushall(delay=0, noreply=False) is raising an exception pymemcache.exceptions.MemcacheServerError: b'Command disabled' . Please see a sample run below with Python v3.9.5. Can you please check why am getting an exception

Sample run output

########$ python3 test.py 
{'a': 'b', 'c': 'd'}
Traceback (most recent call last):
  File "/Users/rpatel8/Downloads/ca-iot-refrigeration/cache-loader/test.py", line 13, in <module>
    client.flush_all(delay=0, noreply=False)
  File "/usr/local/lib/python3.9/site-packages/pymemcache/client/base.py", line 887, in flush_all
    results = self._misc_cmd([cmd], b'flush_all', noreply)
  File "/usr/local/lib/python3.9/site-packages/pymemcache/client/base.py", line 1137, in _misc_cmd
    self._raise_errors(line, cmd_name)
  File "/usr/local/lib/python3.9/site-packages/pymemcache/client/base.py", line 940, in _raise_errors
    raise MemcacheServerError(error)
pymemcache.exceptions.MemcacheServerError: b'Command disabled'
cgordon commented 2 years ago

What do you have running on port 7642? Is it memcached or a proxy of some sort? If it is memcached, do you have the "--disable-flush-all" (or "-F") flag passed to it?

rikeshpatel14 commented 2 years ago

Seems the flush command was disabled. Re-enabling it worked fine. Thank you