GithubHelp home page GithubHelp logo

Comments (2)

weiqinyang avatar weiqinyang commented on June 14, 2024

Modified the code AscIIClient.java as the up mentioned, it may occuer other error: set Object to memcached,like ArrayList Object,it can't be getted correcttly.

from memcached-java-client.

mengli avatar mengli commented on June 14, 2024

Hi weiqinyang,

I try to store and get Java object with array list type, and our client works correctly.
The following is my test case:

package com.schooner.MemCached;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.danga.MemCached.MemCachedClient;
import com.danga.MemCached.SockIOPool;

public class Test {

public static final class TestClass implements Serializable {

    private static final long serialVersionUID = -6676639726514578903L;
    private String field1;
    private String field2;
    private Integer field3;

    public TestClass(String field1, String field2, Integer field3) {
        this.field1 = field1;
        this.field2 = field2;
        this.field3 = field3;
    }

    public String getField1() {
        return this.field1;
    }

    public String getField2() {
        return this.field2;
    }

    public Integer getField3() {
        return this.field3;
    }

    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (!(o instanceof TestClass))
            return false;

        TestClass obj = (TestClass) o;

        return ((this.field1 == obj.getField1() || (this.field1 != null && this.field1.equals(obj.getField1())))
                && (this.field2 == obj.getField2() || (this.field2 != null && this.field2.equals(obj.getField2()))) && (this.field3 == obj
                .getField3() || (this.field3 != null && this.field3.equals(obj.getField3()))));
    }
}

public static void main(String[] args) throws Exception {
    String servers = System.getProperty("memcached.host");
    String[] serverlist = servers.split(",");

    // initialize the pool for memcache servers
    SockIOPool pool = SockIOPool.getInstance("test");
    pool.setBufferSize(3 * 1024 * 1024);
    pool.setServers(serverlist);
    pool.initialize();

    MemCachedClient mc = new MemCachedClient("test");
    List<TestClass> list = new ArrayList<TestClass>();

    for (int i = 0; i < 10; i++) {
        list.add(new TestClass("value" + i, "value" + i, i));
    }
    mc.set("TestClass", list);
    List<TestClass> ret = (List<TestClass>)mc.get("TestClass");
    for (int i = 0; i < 10; i++) {
        System.out.println(list.get(i).getField1());
    }
}

}

Could you give a try and update your feedback?

Meng Li

from memcached-java-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.