memcached命令知识

memcached安装配置     

      yum install memcached
      memcached最大的缓存单位为1M,大于1M的单项数据将不会缓存
      memcached是基于文本协议的,所以可以用telnet命令直接进行与其进行交互
      memcached默认没有安全认证机制

      要想操作redis或者memcached服务器 必须首先安装相关客户端工具库

[root@localhost myapp]# yum install telnet
#查看memcached帮助手册支持的数据类型
[root@localhost ~]# less /usr/share/doc/memcached-1.4.15/protocol.txt
#使用telnet充当memcached的客户端
[root@localhost myapp]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats
STAT pid 22529
STAT uptime 403
STAT time 1531906347
#memcached指定30字节长度后就必须存储30个字节的内容
#大于或者小于30个字节都会导致存储失败
#错误示例
add mykey 1 120 30
  www.baidu.com
get mykey

#正确示例
set m 1 60 5 
aaaaa
STORED
get m
VALUE m 1 5
aaaaa
END
操作memcached

memcached命令类型

    统计类:stats, stats items, stats slabs, stats sizes
    存储类:set, add, replace, append, prepend
   命令格式:<command name> <key> <flags> <exptime> <bytes>
                     <cas unique>
   检索类:get, delete, incr/decr
   清空:flush_all

   示例:
           telnet> add KEY <flags> <expiretime> <bytes>
           telnet> VALUE

memcahed程序的常用选项

     -m <num>:Use <num> MB memory max to use for object storage; the default is 64 megabytes.
     -c <num>: Use <num> max simultaneous connections; the default is 1024.
     -u <username>:以指定的用户身份来运行进程;
     -l <ip_addr>:监听的IP地址,默认为本机所有地址;
     -p <num>:监听的TCP端口, the default is port 11211.
     -U <num>:Listen on UDP port <num>, the default is port 11211, 0 is off.
     -M:内存耗尽时,不执行LRU清理缓存,而是拒绝存入新的缓存项,直到有多余的空间可用时为止;
     -f <factor>:增长因子;默认是1.25;
     -t <threads>:启动的用于响应用户请求的线程数;

     memcached默认没有认证机制,可借用于SASL进行认证;
     SASL:Simple Authentication Secure Layer

原文地址:https://www.cnblogs.com/yxh168/p/9332243.html