http://www.runoob.com/memcached/memcached-cas.html

https://github.com/memcached/memcached/blob/master/doc/protocol.txt  很重要,解释了所有相关含义

==============================

[root@cn-21 ~]# ps -ef|grep mem
systemd+  3338  3319  0  2017 ?        01:13:09 memcached
root     29927 29897  0 15:34 pts/1    00:00:00 grep --color=auto mem
[root@cn-21 ~]# rpm -qa|grep mem
memcached-1.4.15-10.el7_3.1.x86_64
[root@cn-21 ~]# rpm -ql memcached
/etc/sysconfig/memcached
/usr/bin/memcached
/usr/bin/memcached-tool
/usr/lib/systemd/system/memcached.service
/usr/share/doc/memcached-1.4.15
/usr/share/doc/memcached-1.4.15/AUTHORS
/usr/share/doc/memcached-1.4.15/CONTRIBUTORS
/usr/share/doc/memcached-1.4.15/COPYING
/usr/share/doc/memcached-1.4.15/ChangeLog
/usr/share/doc/memcached-1.4.15/NEWS
/usr/share/doc/memcached-1.4.15/README.md
/usr/share/doc/memcached-1.4.15/protocol.txt
/usr/share/doc/memcached-1.4.15/readme.txt
/usr/share/doc/memcached-1.4.15/threads.txt
/usr/share/man/man1/memcached-tool.1.gz
/usr/share/man/man1/memcached.1.gz
[root@cn-21 ~]# cat /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""

==============================

Memcached本身是使用C开发的,客户端可以是php、C#、或者java。

==============================

命令汇总
stats items
stats sizes
set runoob 0 900 9
get runoob
flush_all
===============================
[root@cn-21 ~]# telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
stats items
END
stats slabs
STAT 7:chunk_size 384
STAT 7:chunks_per_page 2730
STAT 7:total_pages 1
STAT 7:total_chunks 2730
STAT 7:used_chunks 0
STAT 7:free_chunks 2730
STAT 7:free_chunks_end 0
STAT 7:mem_requested 0
STAT 7:get_hits 72
STAT 7:cmd_set 49
STAT 7:delete_hits 18
STAT 7:incr_hits 0
STAT 7:decr_hits 0
STAT 7:cas_hits 0
STAT 7:cas_badval 0
STAT 7:touch_hits 0
STAT 9:chunk_size 600
STAT 9:chunks_per_page 1747
STAT 9:total_pages 1
STAT 9:total_chunks 1747
STAT 9:used_chunks 0
STAT 9:free_chunks 1747
STAT 9:free_chunks_end 0
STAT 9:mem_requested 0
STAT 9:get_hits 4
STAT 9:cmd_set 2
STAT 9:delete_hits 0
STAT 9:incr_hits 0
STAT 9:decr_hits 0
STAT 9:cas_hits 0
STAT 9:cas_badval 0
STAT 9:touch_hits 0
STAT 10:chunk_size 752
STAT 10:chunks_per_page 1394
STAT 10:total_pages 1
STAT 10:total_chunks 1394
STAT 10:used_chunks 0
STAT 10:free_chunks 1394
STAT 10:free_chunks_end 0
STAT 10:mem_requested 0
STAT 10:get_hits 82
STAT 10:cmd_set 44
STAT 10:delete_hits 0
STAT 10:incr_hits 0
STAT 10:decr_hits 0
STAT 10:cas_hits 0
STAT 10:cas_badval 0
STAT 10:touch_hits 0
STAT 11:chunk_size 944
STAT 11:chunks_per_page 1110
STAT 11:total_pages 1
STAT 11:total_chunks 1110
STAT 11:used_chunks 0
STAT 11:free_chunks 1110
STAT 11:free_chunks_end 0
STAT 11:mem_requested 0
STAT 11:get_hits 8
STAT 11:cmd_set 2
STAT 11:delete_hits 0
STAT 11:incr_hits 0
STAT 11:decr_hits 0
STAT 11:cas_hits 0
STAT 11:cas_badval 0
STAT 11:touch_hits 0
STAT active_slabs 4
STAT total_malloced 4194304
END

=====================

stats settings
STAT maxbytes 67108864
STAT maxconns 1024
STAT tcpport 11211
STAT udpport 11211
STAT inter NULL
STAT verbosity 0
STAT oldest 0
STAT evictions on
STAT domain_socket NULL
STAT umask 700
STAT growth_factor 1.25
STAT chunk_size 48
STAT num_threads 4
STAT num_threads_per_udp 4
STAT stat_key_prefix :
STAT detail_enabled no
STAT reqs_per_event 20
STAT cas_enabled yes
STAT tcp_backlog 1024
STAT binding_protocol auto-negotiate
STAT auth_enabled_sasl no
STAT item_size_max 1048576
END

=====================

stats sizes
STAT sizes_status disabled

set runoob 0 900 9
memcached
STORED

get runoob
VALUE runoob 0 9
memcached
END

flush_all
OK
get runoob
END

======================

<command name> <key> <flags> <exptime> <bytes> [noreply]\r\n
cas <key> <flags> <exptime> <bytes> <cas unique> [noreply]\r\n
按秒算,5是数据库的长度,即5字节,多于5和小于5都会报错
set file 0 300 5
iiiiii
CLIENT_ERROR bad data chunk
ERROR
set file 0 300 5
iiii

CLIENT_ERROR bad data chunk
ERROR
set file 0 300 5
iiiii
STORED

======================

[root@cn-21 ~]# memcached-tool localhost:11211  stats
#localhost:11211   Field       Value
         accepting_conns           1
               auth_cmds           0
             auth_errors           0
                   bytes           0
              bytes_read   139360283
           bytes_written   232272906
              cas_badval           0
                cas_hits           0
              cas_misses           0
               cmd_flush         147
                 cmd_get         298
                 cmd_set          99
               cmd_touch           0
             conn_yields           0
   connection_structures          52
   crawler_items_checked           1
       crawler_reclaimed           0
        curr_connections          38
              curr_items           0
               decr_hits           0
             decr_misses           0
             delete_hits          18
           delete_misses           0
         direct_reclaims           0
          evicted_active           0
       evicted_unfetched           0
               evictions           0
       expired_unfetched          34
             get_expired           0
             get_flushed           0
                get_hits         168
              get_misses         130
              hash_bytes      524288
       hash_is_expanding           0
        hash_power_level          16
               incr_hits           0
             incr_misses           0
                libevent 2.0.21-stable
          limit_maxbytes    67108864
     listen_disabled_num           0
        log_watcher_sent           0
     log_watcher_skipped           0
      log_worker_dropped           0
      log_worker_written           0
       lru_bumps_dropped           0
     lru_crawler_running           0
      lru_crawler_starts      203490
  lru_maintainer_juggles    12327347
       lrutail_reflocked          22
            malloc_fails           0
         max_connections        1024
           moves_to_cold         112
           moves_to_warm          27
        moves_within_lru           0
                     pid           1
            pointer_size          64
               reclaimed          41
    rejected_connections           0
            reserved_fds          20
           rusage_system 3602.709727
             rusage_user  795.646915
   slab_global_page_pool           0
slab_reassign_busy_deletes           0
slab_reassign_busy_items           0
slab_reassign_chunk_rescues           0
slab_reassign_evictions_nomem           0
slab_reassign_inline_reclaim           0
   slab_reassign_rescues           0
   slab_reassign_running           0
             slabs_moved           0
                 threads           4
                    time  1515488925
time_in_listen_disabled_us           0
       total_connections         177
             total_items          98
              touch_hits           0
            touch_misses           0
                  uptime     2770390
                 version       1.5.3

=============================================

redis

wget http://download.redis.io/releases/redis-4.0.6.tar.gz
cd redis-4.0.6
make
cd src/
./redis-server
./redis-cli
先启动server,再用cli去连接,开两个终端窗口
==============================
[root@localhost src]# ./redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> exit
[root@localhost src]# ./redis-cli
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> CONFIG GET *
127.0.0.1:6379> client list
id=3 addr=127.0.0.1:15897 fd=8 name= age=617 idle=520 flags=N db=0 sub=1 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=subscribe
id=4 addr=127.0.0.1:15921 fd=9 name= age=584 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client

[root@localhost src]# ./redis-benchmark -n 10000

配置这个之后,远程才可以连接
127.0.0.1:6379> CONFIG SET protected-mode no
OK
127.0.0.1:6379> set aa bb
OK
=====================
package java20180118;
import redis.clients.jedis.Jedis;

public class Redis {
    public static void main(String[] args) {
        //连接本地的 Redis 服务
        Jedis jedis = new Jedis("192.168.3.225");
        System.out.println("连接成功");
        //查看服务是否运行
        System.out.println("服务正在运行: "+jedis.get("aa"));
    }
}
=======================

memcached-redis的更多相关文章

  1. Python自动化 【第十一篇】:Python进阶-RabbitMQ队列/Memcached/Redis

     本节内容: RabbitMQ队列 Memcached Redis 1.  RabbitMQ 安装 http://www.rabbitmq.com/install-standalone-mac.htm ...

  2. python对缓存(memcached,redis)的操作

    1.Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的 ...

  3. centos7下搭建nginx+php7.1+mariadb+memcached+redis

    一.环境准备 1.首先介绍一下环境,以及我们今天的主角们 我用的环境是最小化安装的centos7,mariadb(江湖传言mysql被oracle收购后,人们担心像java一样毁在oracle手上于是 ...

  4. Memcached & Redis使用

    Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached ...

  5. Memcached, Redis, MongoDB区别

    mongodb和memcached不是一个范畴内的东西.mongodb是文档型的非关系型数据库,其优势在于查询功能比较强大,能存储海量数据.mongodb和memcached不存在谁替换谁的问题. 和 ...

  6. 17.Python笔记之memcached&redis

    作者:刘耀 博客:www.liuyao.me 博客园:www.cnblogs.com/liu-yao 一.Memcached 1.介绍 Memcached 是一个高性能的分布式内存对象缓存系统,用于动 ...

  7. memcached/redis安全性

    最近看到说redis,memcached服务器安全的问题,想想也是,使用这两种服务N年了,由于历史问题吧,工作中基本是以memcached为主,后来才慢慢引入运用redis.由于memcached是没 ...

  8. Memcached·Redis缓存的基本操作

    Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...

  9. NOSQL学习之一:Memcached, Redis, MongoDB区别

    Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理. Memcached是一个自由开源的,高性能,分布式内存对象缓存系统. MongoDB是一个基于分布 ...

  10. 缓存:Memcached Redis

    一.Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的 ...

随机推荐

  1. 【Python】【自动化测试】【pytest】【常用命令行选项】

    https://www.cnblogs.com/cnkemi/p/9989019.html http://www.cnblogs.com/cnkemi/p/10002788.html pytest 常 ...

  2. Redis实现文章投票功能

    Redis的具体操作这里就不说了,说一下需求和设计思路. 需求:自己实现一个文章投票的功能1.能够按照时间分页倒叙查看文章信息2.能够给文章投票,一个用户给一篇文章只能投票一次3.需要记录分值.每次投 ...

  3. HTML辅助方法

    顾名思义,HTML辅助方法(HTML Helper)就是用来辅助产生HTML之用,在开发View的时候一定会面对许多HTML标签,处理这些HTML的工作非常繁琐,为了降低View的复杂度,可以使用HT ...

  4. 第二周javaweb学习进度表

      第一周 所花时间 三天 代码量 200行 博客量 3篇 知识点了解到的 学习到了HTML编程语言的相关知识比如checkbox复选框和radio单选按钮以及form表单的使用方法,form表单可以 ...

  5. dedecmsv5.7 前台模版里输出变量

    如何在PHP文件查询出来的数据赋值给前端页面展示出来? 例如: PHP文件:agency.php require_once(dirname(__FILE__) . '/../../include/co ...

  6. python学习(五)

  7. 『Numpy』内存分析_利用共享内存创建数组

    引.内存探究常用函数 id(),查询对象标识,通常返回的是对象的地址 sys.getsizeof(),返回的是 这个对象所占用的空间大小,对于数组来说,除了数组中每个值占用空间外,数组对象还会存储数组 ...

  8. Python *Mix_w8

    文件操作的函数 文件可迭代 open(文件名(路径), mode="?", encoding="字符集") f = open("../Python/是 ...

  9. A JSON example

    heroes.html<!DOCTYPE html> <html> <head> <meta charset="utf-8"> &l ...

  10. effective java——31用实例域代替序数

    1,永远不要根据枚举的序数导出与它关联的值,而是要将他保存在一个实例域中.(ordinal()) public enum Ensemble { SOLO, DUET, TRIO, QUARTET, Q ...