Java中memcached 如何获取所有未过期的key?
Java中memcached 如何获取所有未过期的key?下面写了一个获取所有key的方法,但是会得到过期的key,如何过滤掉?
public static List<String> getAllKey(String reg) { List<String> keylist = new ArrayList<String>();
Map<String, Map<String, String>> statsItems = memcachedClient.statsItems(); //获取所有items
Map<String, String> statsItems_sub = null;
String server = null;
String statsItems_sub_key = null;
int items_number = 0;
Map<String, Map<String, String>> statsCacheDump = null;
Map<String, String> statsCacheDump_sub = null;
String statsCacheDumpsub_key = null;
for (Iterator<String> iterator = statsItems.keySet().iterator(); iterator.hasNext(); ) {
server = iterator.next(); //server地址
keylist.add(server);
statsItems_sub = statsItems.get(server);
for (Iterator<String> iterator_item = statsItems_sub.keySet().iterator(); iterator_item.hasNext(); ) {
statsItems_sub_key = iterator_item.next();
if (statsItems_sub_key.toUpperCase().startsWith("items:".toUpperCase()) && statsItems_sub_key.toUpperCase().endsWith(":number".toUpperCase())) {
items_number = Integer.parseInt(statsItems_sub.get(statsItems_sub_key).trim());
statsCacheDump = memcachedClient.statsCacheDump(new String[]{server}, Integer.parseInt(statsItems_sub_key.split(":")[1].trim()), items_number); //获取一个item
for (Iterator<String> statsCacheDump_iterator = statsCacheDump.keySet().iterator(); statsCacheDump_iterator.hasNext(); ) {
statsCacheDump_sub = statsCacheDump.get(statsCacheDump_iterator.next());
for (Iterator<String> iterator_keys = statsCacheDump_sub.keySet().iterator(); iterator_keys.hasNext(); ) {
statsCacheDumpsub_key = (String) iterator_keys.next(); //获取item的key
if(statsCacheDumpsub_key.contains(reg)){
keylist.add(statsCacheDumpsub_key);
}
}
}
}
}
}
return keylist;
}
以上是 Java中memcached 如何获取所有未过期的key? 的全部内容, 来源链接: utcz.com/p/945486.html