【问题标题】:Retrieve Memcached values using Whalin memcached使用 Whalin memcached 检索 Memcached 值
【发布时间】:2015-05-29 09:44:48
【问题描述】:

我从 memcached 获取值并尝试转换类列表,但我得到像这样的类异常 java.lang.String cannot be cast to java.util.List 有人可以帮忙吗?主题是POJO类

代码

MemCachedClient mc = new MemCachedClient();
List<Topic> topicList = (List<Topic>) mc.get("topics");

错误

java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List

在内存缓存中,关键“主题”仅包含主题类列表

我的内存缓存添加和获取代码是 public void add(String key, Object value) { System.out.println("The Object Values are:"+value.getClass().getName()); mcClient.set(key, value); } public Object get(String fqn) { System.out.println("Gets class Name:"+mcClient.get(fqn).getClass()); return mcClient.get(fqn); }

我的结果是 The Object Values are:java.util.LinkedList Gets class Name:class java.lang.String

在添加到 memcached 时,它位于链表中,但我从 memcache 中获取值,它位于字符串中,我不知道为什么会这样。

谁能帮忙....???

【问题讨论】:

  • 请向我们展示导致异常和 StackTrace 的代码。请编辑您的帖子并在此处添加信息

标签: java memcached


【解决方案1】:

看起来 mc.get("topics") 正在返回 List&lt;String&gt; 而不是 List&lt;Topic&gt; 如您所料。你能仔细检查一下你存储在缓存中的内容吗?

【讨论】:

  • 是的,我只存储了List&lt;Topic&gt;。我认为 whalin Memcached 客户端 get 方法返回为 String Object Retrieve a key from the server, using a specific hash. If the data was compressed or serialized when compressed, it will automatically be decompressed or serialized, as appropriate. (Inclusive or) Non-serialized data will be returned as a string, so explicit conversion to numeric types will be necessary, if desired
猜你喜欢
  • 1970-01-01
  • 2013-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-23
  • 1970-01-01
相关资源
最近更新 更多