Windows + MemCached

来源:互联网 发布:mac怎么解压 编辑:程序博客网 时间:2024/06/16 12:53

1:下载MemCached

       http://code.jellycan.com/

       下载地址:http://code.jellycan.com/files/memcached-1.2.6-win32-bin.zip


2:解压

      如解压到 D:\sw\server\setupfiles\memcached\memcached.exe


3:安装

      开始-->运行-->cmd 调出命令窗口,使用命令进入到memcached的目录, 输入:
      memcached.exe -d install   
      memcached.exe -d start      

      这样memcached就成为windows服务了,如果需要关闭memcached的服务,切换到memcached的目录关闭服务,输入:
      memcached.exe -d stop|shutdown


4:设置memcached

      启动该服务后,memcached服务默认占用的端口是11211,占用的最大内存默认是64M。
      修改端口为10000
      修改内存为512,则切換到memcache目錄,输入: 
      memcached.exe -p 10000 -m 512 -d start
      -p 表示要修改的端口, -m表示占用的最大内存(单位为M)


5:常用命令

     1. telnet到memcache服务器,如:telnet 192.168.1.120 11211(11211是memcache的默认端口)
     2. stats 查看基本信息
     3. stats items 查看items
     4. get key(key 为 item后面的字符串即键)
     5. -c 最大同时连接数,默认是1024
     6. -f 块大小增长因子,默认是1.25
     7. -n 最小分配空间,key+value+flags默认是48
     8. -h 显示帮助


6:MemCached管理工具memadmin

     1)下载地址

           https://github.com/junstor/memadmin

     2)安装

           前提是php需要安装memcache,请参考

           下载后解压到apche网页程序根目录,配置config.php的用户名和密码即可。

            


7:测试

      1)确保启动了Memcached

      2)php测试代码

<?php    $mem = new Memcache;    $mem->pconnect('127.0.0.1',11211,3);    $mem->set("k-bryan", "This is a test!", 0, 60);    $val = $mem->get("k-bryan");    echo $val;?>

8:.NET memcached 客户端dll

    1)下载地址

          http://sourceforge.net/projects/memcacheddotnet/

    2)代码

          引入dll  :  using Memcached.ClientLibrary;

string[] serverlist = { "127.0.0.1" };SockIOPool siop = SockIOPool.GetInstance();siop.SetServers(serverlist);siop.InitConnections = 3;siop.MinConnections = 3;siop.MaxConnections = 5;siop.SocketConnectTimeout = 1000;siop.SocketTimeout = 3000;siop.MaintenanceSleep = 30;siop.Failover = true;siop.Nagle = false;siop.Initialize();MemcachedClient mc = new MemcachedClient();mc.EnableCompression = false;mc.Set("mykey", "test...");string value = (string)mc.Get("mykey");



















0 0
原创粉丝点击