Redis 官网

http://www.redis.cn

Windows 安装

  • scoop install redis

    Linux 安装

    下载并安装

    1. wget http://download.redis.io/releases/redis-6.0.8.tar.gz
    2. tar xzf redis-6.0.8.tar.gz
    3. cd redis-6.0.8
    4. make

    启动Redis(默认启动模式)

  • cd src

  • ./redis-server

后台启动模式配置文件

Docker 安装

  • docker pull redis
  • docker run -itd --name redis-test -p 6379:6379 redis \bin\bash
  • docker exec -it containerID \bin\bash

    Redis 连接测试

  • redis-cli ping // pong

  • set name hellochen
  • get name // "hellochen"

    Redis 性能测试

    1. Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]
    2. -h <hostname> Server hostname (default 127.0.0.1)
    3. -p <port> Server port (default 6379)
    4. -s <socket> Server socket (overrides host and port)
    5. -a <password> Password for Redis Auth
    6. -c <clients> Number of parallel connections (default 50)
    7. -n <requests> Total number of requests (default 100000)
    8. -d <size> Data size of SET/GET value in bytes (default 2)
    9. -dbnum <db> SELECT the specified db number (default 0)
    10. -k <boolean> 1=keep alive 0=reconnect (default 1)
    11. -r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD
    12. Using this option the benchmark will expand the string __rand_int__
    13. inside an argument with a 12 digits number in the specified range
    14. from 0 to keyspacelen-1. The substitution changes every time a command
    15. is executed. Default tests use this to hit random keys in the
    16. specified range.
    17. -P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline).
    18. -q Quiet. Just show query/sec values
    19. --csv Output in CSV format
    20. -l Loop. Run the tests forever
    21. -t <tests> Only run the comma separated list of tests. The test
    22. names are the same as the ones produced as output.
    23. -I Idle mode. Just open N idle connections and wait.
    $ redis-benchmark -n 10000  -q
    PING_INLINE: 16393.44 requests per second
    PING_BULK: 16393.44 requests per second
    SET: 15432.10 requests per second
    GET: 16313.21 requests per second
    INCR: 16556.29 requests per second
    LPUSH: 15220.70 requests per second
    RPUSH: 14471.78 requests per second
    LPOP: 15060.24 requests per second
    RPOP: 16129.03 requests per second
    SADD: 16339.87 requests per second
    SPOP: 15105.74 requests per second
    LPUSH (needed to benchmark LRANGE): 13736.26 requests per second
    LRANGE_100 (first 100 elements): 9652.51 requests per second
    LRANGE_300 (first 300 elements): 5238.34 requests per second
    LRANGE_500 (first 450 elements): 3759.40 requests per second
    LRANGE_600 (first 600 elements): 3608.81 requests per second
    MSET (10 keys): 13927.58 requests per second
    

    Redis 远程连接配置

  1. 修改redis服务器的配置文件

本机安装的redis-4.0.14默认的配置文件 redis.conf 设置
  绑定本机地址:bind 127.0.0.1
  开启保护模式:protected-mode yes
  此时连接,服务器是拒绝的

[root@hellochen redis]# ./redis-cli -h 192.168.100.109  -p  6379 
Could not connect to Redis at 192.168.100.109:6379: Connection refused
Could not connect to Redis at 192.168.100.109:6379: Connection refused
not connected> eixt
  1. 配置文件比较大,我们通过ctrl + F 查找关键字修改为:

  bind 0.0.0.0
  protected-mode no

  1. 使用redis客户端连接

redis-cli -h 192.168.123.36