Install and use Redis in the docker environment on mac

One: Introduction to Redis

Redis is completely free and open source, a high-performance key-value database
Redis compared with other key-value caching products:

  • High performance, support data persistence
  • Multiple data structures: list, set, zset, hash, etc. storage
  • Support data backup
  • Support transaction, atomicity of data (either do not do / do all)

Redis application scenarios

  • Cache (excellent read and write performance)
  • Counting & message system (high concurrency, publish/subscribe blocking queue function)
  • Distributed session session&distributed lock (seckill)

Redis vs Mongo

  • The storage method is different: key-value vs document
  • Usage & reliability are different: MongoDB: SQL&ACID support
  • Different application scenarios: high-performance cache vs massive data analysis

Two: install redis on docker on mac

  • Run in docker-compoese mode:
    create docker-compose.ymlfiles
    version: '3'
    services: 
      redis-test:
        image: 'redis'
        restart: always
        container_name: 'redis-test'
        ports: 
          - 15001:6379
        volumes:
          - /Users/zyy/学习/redistest:/data
        command: ["redis-server", "--requirepass", "123456"]
    
    Run in the file directory:docker-compose up -d
  • The docker run command runs:
    docker run -itd --restart=always --name redis-test -p 15001:6379 -v /Users/zyy/学习/redistest:/data redis redis-server --requirepass=123456
    

docker logs -f redis-test(Redis-test is the container name or container id)
View the log information of the container named redis-test

Redis configuration file reference: https://github.com/redis/redis/blob/unstable/redis.conf

Redis installation summary:

  • Manual installation (suitable for unfamiliar Docker/no Docker environment)
  • Docker installation (recommended)
  • Configure redis.conf, cache redis data (required for production)

Three: Redis CLi

Command-line operation redis
redis command reference:
http://doc.redisfans.com/

Enter the redis container, redis-cliconnect to the redis service, and auth 123456log in to redis
Insert picture description here

Four: Redis GUI tool

  • Another Redis DeskTop Manager (free)
  • Medis (fees, can be built by yourself)
  • Redis Desktop Manager (charged)

Five: Redis node.js integration

https://www.npmjs.com/package/redis

Guess you like

Origin blog.csdn.net/weixin_40693643/article/details/113477212