Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python-memcached : Unable to memcache a mysql output. ( UnpickleableError: Cannot pickle objects )

For some reason memcache does not seem to like

result

in this following code

db.query("select * from TABLE order by ID desc limit 70")
result = db.store_result()
m.set('1',result,60)

This is the error in apache error_log:

m.set('1',result,60)
File "/usr/lib/python2.6/site-packages/memcache.py", line 466, in set
return self._set("set", key, val, time, min_compress_len)
File "/usr/lib/python2.6/site-packages/memcache.py", line 639, in _set
store_info = self._val_to_store_info(val, min_compress_len)
File "/usr/lib/python2.6/site-packages/memcache.py", line 615, in _val_to_store_info
pickler.dump(val)
UnpickleableError: Cannot pickle objects

Something is probably going on with the "result".

otherwise instead of "result".. something else such as..

 m.set('1','test',60)

works just fine.

like image 607
Sümer Kolçak Avatar asked Oct 31 '22 20:10

Sümer Kolçak


1 Answers

store_result instructs MySQL to store the result of your query locally, and returns a reference to that "result object". It does not actually return a list of rows.

To actually get the rows:

rows = result.fetch_row(maxrows=0)  # Actually fetches all the rows
m.set('1', rows, 60)

Now, it'd be best to instantiate a cursor than to use _mysql directly.

like image 141
Thomas Orozco Avatar answered Nov 08 '22 06:11

Thomas Orozco