ssyuan / memlink

Automatically exported from code.google.com/p/memlink
0 stars 0 forks source link

有一个关于memlink过滤的问题想请教下。 #20

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
import com.googlecode.memlink.*;
import java.util.*;
import java.lang.*;

public class test_client
{
    static {
        try{
            System.out.println("try load library: libcmemlink.so");
            System.loadLibrary("cmemlink");
        }catch (UnsatisfiedLinkError e) {
            System.err.println("library libcmemlink.so load error! " + e); 
            System.exit(1);
        }   
        System.out.println("load ok!");
    }

    public static void test_create_table(MemLinkClient m, String name)
    {
        int ret;
        int valuelen = 12;
        String maskformat = "4:3:1";

        ret = m.createTableList(name, valuelen, maskformat);
        if (0 != ret){
            System.out.println("create error:" + ret);
            return;
        }else{
            System.out.println("create " + name); 
        }
    }

    public static void test_insert(MemLinkClient m, String table , String key)
    {
        int i = 0;
        int ret = 0;
        int num = 12;
        //String value = "012345678912";

        for (i = 0; i < num; i++) {
            String value = String.format(i+1+"ccc");
            if(i == 0){
                ret = m.insert(table ,key, value.getBytes(), "8:3:2", 0);
            }else{
                ret = m.insert(table ,key, value.getBytes(), "8:3:1", 0);
            }

            if (0 != ret)
            {
                System.out.println("errr insert!");
                return;
            }
        }

        System.out.println("insert 200");               
    }

    public static void test_stat(MemLinkClient m, String table, String key)
    {        
        int ret;
        MemLinkStat stat = new MemLinkStat();
        ret = m.stat(table ,key, stat);
        if (cmemlink.MEMLINK_OK != ret)
        {
            System.out.println("errr stat!");
            return;
        }
        if (stat.getData() != 12 || stat.getData_used() != 12)
        {    
            System.out.println("errr stat result!");
            return;
        }
    }

    public static void test_range(MemLinkClient m, String table, String key)
    {        
        int ret;
        MemLinkResult rs = new MemLinkResult();
        ret = m.range(table , key, cmemlink.MEMLINK_VALUE_VISIBLE, "::3", 0, 12, rs);
        if (cmemlink.MEMLINK_OK != ret)
        {
            System.out.println("err range!");
            return;
        }
        System.out.println("range count: " + rs.getCount());
        MemLinkItem item = rs.getItems();
        while (null != item)
        {
            String v = new String(item.getValue());
            System.out.println("value: " + v + " length:" + v.length());
            item = item.getNext();
        }
    }

    public static void test_count(MemLinkClient m, String table, String key)
    {
        int ret;

        MemLinkCount count = new MemLinkCount();
        ret = m.count(table , key, "8:3:1", count);
        if (cmemlink.MEMLINK_OK != ret)
        {
            System.out.println("err count!");
            return;
        }
        System.out.println("count.visible: " + count.getVisible_count() + "\ncount.tagdel: " + count.getTagdel_count());                
    }

    public static void test_move(MemLinkClient m, String table, String key)
    {
        int ret;
        int i = 0;

        String value = String.format("%012d", i); //the last one
        ret = m.move( table ,key, value.getBytes(), 0); //move it to first
        if (0 != ret)
        {
            System.out.println("err tag");
            return;
        }
    }

    public static void test_tag(MemLinkClient m, String table, String key)
    {
        int ret;
        int i = 100;

        String value = String.format("%012d", i);
        ret = m.tag( table , key, value.getBytes(), cmemlink.MEMLINK_TAG_DEL); //tag value
        if (0 != ret)
        {
            System.out.println("err tag");
            return;
        }
    }

    public static void test_del(MemLinkClient m, String table, String key)
    {
        int ret;
        int i = 199;

        String value = String.format("%012d", i);
        ret = m.tag(table , key, value.getBytes(), cmemlink.MEMLINK_TAG_DEL);
        if (0 != ret)
        {
            System.out.println("err tag");
            return;
        }
    }

    public static void main(String [] args)
    {
        //String str = System.getProperty("java.library.path");
        //System.out.println(str);

        MemLinkClient m = new MemLinkClient("127.0.0.1", 11001, 11002, 10);
        String name = "testtable";
        String key = name + ".haha";

//      test_create_table(m, name);
//      test_insert(m, name, key);
//      test_stat(m, name, key);
//      System.out.println("\nrange1: ");
        test_range(m, name , key);
        test_count(m, name ,  key);
        //test_update(m, key);
//      test_tag(m,name ,  key);
//      test_del(m,name, key);
//      System.out.println("\nrange2: ");
//      test_range(m, name , key);

        m.destroy();
    }
}

试了最新的r802 
memlink,我用上面的java代码,我添加了attrstr为 8:3:1  和 attrstr 
8:3:2 两种数据,我用  ::1   range时候,可以匹配出 8:3:1的 ,  
用 ::2 可以匹配出 8:3:2  的数据,但是,为何我使用  ::3  
过滤时候,却把  8:3:1  
的数据匹配出来了,不是应该没有找到匹配的吗?   
难道memlink不支持这样的过滤吗?  

Original issue reported on code.google.com by ickl...@gmail.com on 10 Sep 2011 at 4:28