我有以下代码:
mongoClient = new MongoClient( "localhost" , 27017 );
db = mongoClient.getDB("hcm");
DBCollection coll = db.getCollection("segment_cell_details");
BasicDBObject query = new BasicDBObject("cell_x", cell_x).append("cell_y", cell_y);
DBCursor cursor = coll.find(query);
接下来,我想在memcached中添加DBCursor:
c = new MemcachedClient(AddrUtil.getAddresses("localhost:11211"));
c.add("Key", 3600, cursor);
然后,系统打印出“不可序列化的对象错误”
那么,如何将查询结果添加到memcached?
答案 0 :(得分:0)
游标是一个懒惰地加载结果的迭代器。您需要添加结果而不是迭代器。我建议将它们添加为序列化JSON。
while (cursor.hasNext())
c.add("key",3600,cursor.next().toString());