memcached 不同客户端存取值问题

本人接触memcached不多,希望下面的问题能帮助到遇到同样问题的同学,作为个人日记记录一下。

昨天调试memcached发现,在手机端存进去的值,java端没取到。

一般我们只关注key和value,发现并无问题;然后好好看了下flags。

查源码发现
cmd = cmdname + " " + key + " " + flags + " " + expiry.getTime() / 1000L + " ";
flags = NativeHandler.getMarkerFlag(value);
继续看源码:
public static final int getMarkerFlag(Object value)
    {
        if(value instanceof Byte)
            return 1;
        if(value instanceof Boolean)
            return 8192;
        if(value instanceof Integer)
            return 4;
        if(value instanceof Long)
            return 16384;
        if(value instanceof Character)
            return 16;
        if(value instanceof String)
            return 32;
        if(value instanceof StringBuffer)
            return 64;
        if(value instanceof Float)
            return 128;
        if(value instanceof Short)
            return 256;
        if(value instanceof Double)
            return 512;
        if(value instanceof Date)
            return 1024;
        if(value instanceof StringBuilder)
            return 2048;
        return !(value instanceof byte[]) ? 0 : 4096;
    }

终于明白了,javastring类型存储默认flags=32。

修正setflags再测试,问题解决。

相关推荐