Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redis记录 #32

Open
lovecn opened this issue Jun 12, 2015 · 2 comments
Open

redis记录 #32

lovecn opened this issue Jun 12, 2015 · 2 comments

Comments

@lovecn
Copy link
Owner

lovecn commented Jun 12, 2015

1: 把表名转换为key前缀 如, tag:
2: 第2段放置用于区分区key的字段--对应mysql中的主键的列名,如userid
3: 第3段放置主键值,如2,3,4...., a , b ,c
4: 第4段,写要存储的列名

用户表 user , 转换为key-value存储
userid username passworde email
9 Lisi 1111111 lisi@163.com

set user:userid:9:username lisi
set user:userid:9:password 111111
set user:userid:9:email lisi@163.com

keys user:userid:9*

2 注意:
在关系型数据中,除主键外,还有可能其他列也步骤查询,
如上表中, username 也是极频繁查询的,往往这种列也是加了索引的.

转换到k-v数据中,则也要相应的生成一条按照该列为主的key-value
Set user:username:lisi:uid 9

这样,我们可以根据username:lisi:uid ,查出userid=9,
再查user:9:password/email ...

完成了根据用户名来查询用户信息


 windows安装配置memcache和memcached
 下载memcached.exe http://code.jellycan.com/files/memcached-1.2.6-win32-bin.zip  
计算机丢失msvcr71.dll问题
 http://www.jb51.net/dll/26630.html   
http://www.jb51.net/dll/msvcr71.dll.html#down
 解压后把文件dll复制到 
64位系统 
C:\Windows\SysWOW64 
32位系统 
C:\Windows\System32 
memcached.exe -d install  用管理员身份运行cmd
memcached.exe -d start
进入telnet localhost 11211
根据版本下载php_memcache.dll http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/php_memcache-3.0.8-5.6-ts-vc11-x86.zip 

    $mem=new Memcache;
    $mem->connect("localhost",11211);   //pconnect长链接
    //$mem->addServer("www.test.com",11221);    //添加多个服务器
    //$mem->addServer("192.168.1.9",11211);

    $mem->add("mystr","this is a memcache test!",MEMCACHE_COMPRESSED,3600);
    $str=$mem->get("mystr");
    echo "string: ".$str."<br />";

    $mem->add("myarr",array("aaa","bbb","ccc","ddd"));
    print_r($mem->get("myarr"));

    echo '<br />';
    class TestC
        {
            var $name="Tom";
            var $age=5;
            var $money=100; 
        }
    $mem->add("myobj",new TestC);

    var_dump($mem->get("myobj"));
    echo '<br />';
    echo $mem->getVersion()."<br />";
    echo '<pre>';
    print_r($mem->getStats());
    echo '</pre>';

    $mem->close();

http://www.phpddt.com/usr/uploads/2012/10/93872356.rar 通过这个文件中的类“memcached”对 memcached 服务进行操作了
@lovecn
Copy link
Owner Author

lovecn commented Jun 13, 2015

http://devdd.sinaapp.com/post-477.html zcount('room_user_set_', 1, '+inf'); //-inf和+inf表示最低和最高score值

@lovecn
Copy link
Owner Author

lovecn commented Jun 14, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant