redis collection 01 episode (cognition, installation)

redis collection 01 episode

python learning directory portal

1. Introduction to Redis

1. Features and advantages

开源的,使用C编写,基于内存且支持持久化
高性能的Key-Value的NoSQL数据库
支持数据类型丰富,字符串strings,散列hashes,列表lists,集合sets,有序集合sorted sets 等
支持多种编程语言(C C++ Python Java PHP ... )

2. Compare with other databases

MySQL : 关系型数据库,表格,基于磁盘,慢
MongoDB:键值对文档型数据库,值为JSON文档,基于磁盘,慢,存储数据类型单一
Redis的诞生是为了解决什么问题?? 
 解决硬盘IO带来的性能瓶颈

3. Application scenarios

使用Redis来缓存一些经常被用到、或者需要耗费大量资源的内容,通过这些内容放到redis里面,程序可以快速读取这些内容
一个网站,如果某个页面经常会被访问到,或者创建页面时消耗的资源比较多,比如需要多次访问数据库、生成时间比较长等,我们可以使用redis将这个页面缓存起来,减轻网站负担,降低网站的延迟,比如说网站首页等

2. Historical origin

1. History

LLOOGG.com helps other websites to count user information, the browsing records sent by each website will be stored in the storage queue, 5-10000 records, extra 5 need to be charged

2. Principle

FIFO mechanism, first-in-first-out, one entry when full, the more websites, the more queues, and the more push and pop operations

3. Technology and problems

Started to use MySQL for hard disk read and write, the speed was very slow, which made it impossible to display in real time, so I wrote a list structure memory database, the performance of the program will not be limited by the hard disk IO, and the persistence function is added.

4.redis database

# In order to solve the load problem, redis was invented

Three. Redis additional functions

1. Endurance

Save the data in the memory to the disk to ensure data security and facilitate data backup and recovery

2. Expiration key function

Set an expiration time for the key, let it automatically delete the
  <save memory space>
  music player within the specified time , daily play ranking, and automatic deletion after expiration

3. Transaction function

Perform multiple operations atomically

4. Master-slave replication

5.Sentinel

4. Installation

1. Ubuntu environment

Install
  sudo apt-get install redis-server server
start
  sudo /etc/init.d/redis-server status | start | stop | restart
Client connection
  redis-cli -h IP address -p port
  redis-cli # default connection to this Machine's 6379 port
  127.0.0.1:6379>ping
  PONG

2. Windows environment

1. Download the installation package
https://github.com/ServiceStack/redis-windows/blob/master/downloads/redis-64.3.0.503.zip
2. Unzip
3. Start the server
Double-click the unzipped redis-server.exe
4 、Client connection
Double click redis-cli.exe after decompression

Problem: The service is terminated after closing the terminal.
Solution: Install the Redis service to the local service

1. Rename redis.windows.conf to redis.conf, as the configuration file of redis service
2. CMD command line, enter the directory where redis-server.exe is located
3. Execute: redis-server --service-install redis.conf --loglevel verbose
4. Computer-Management-Service-Redis-Start

  • Uninstall
    to the path where redis-server.exe is located and execute:
    1. redis-server --service-uninstall
    2. sc delete Redis

Five. Configuration file

1. The path where the configuration file is located

1、Ubuntu
    /etc/redis/redis.conf

2、windows 下载解压后的redis文件夹中
    redis.windows.conf
    redis.conf

2. Set the connection password

1、requirepass 密码
2、重启服务
   sudo /etc/init.d/redis-server restart
3、客户端连接
   redis-cli -h 127.0.0.1 -p 6379 -a 123456
   127.0.0.1:6379>ping

3. Allow remote connections

sudo vi /ect/redis/redis.conf

1、# 注释掉IP地址绑定69行
   bind 127.0.0.1
2、# 关闭保护模式(默认开始,不允许外部网络访问)88行(把yes改为no)
   protected-mode no
3、# 重启redis服务
   sudo /etc/init.d/redis-server restart

4. Remote connection test

  • Windows connect to Ubuntu's Redis service

5. cmd command line

1、d:
2、cd Redis3.0
3、redis-cli -h x.x.x.x -a 123456
4、x.x.x.x:6379>ping

Guess you like

Origin blog.csdn.net/weixin_38640052/article/details/107758703