Redis Overview and Installation

A, NoSQL database Introduction

Before introducing NoSQL, first discuss the classification techniques.

  In the MVC project development process, we use RDBMS (relational database) + jdbc solve functional problems M layer, to solve the problem with Java C layer, to solve the problem with jsp + HTML V layer, coupled with the use of SVN use version control to solve the problem, do after the completion of the project development, the project will be posted on Tomcat under Linux for users to access more of these techniques are classified as functional solve technical problems.

  But if you just use the above techniques to solve functional problems, the project development is very difficult, difficult to extend and complete the project, so there will be SpringMVC / Struts, Spring, Mybatis / Hibernate frameworks and other techniques that are classified as technical solve the scalability problem.

  When a project is developed, can handle a normal business, performance issues was put on the desktop. In dealing with performance issues, there is NoSQL, Hadoop, Nginx, MQ, etc. to meet the needs of developers to improve performance.

The Redis presented here belongs to NoSQL.

  Summarize the role of the Redis: When a user requests need to access the database, logic layer (C layer) will look to go to Redis data, if there is a direct return, if Redis is not, go find data in MySQL. MySQL to find the data and returns the data stored in this Redis in response to the next request for the same data may occur. That is done with a relational database cache.

  NoSQL (Not Only SQL), refers to non-relational databases, so as to save key-value pairs of data, unlike the relational database storage is dependent on the business logic, in a simple manner NoSQL key-value pairs of data memory, does not follow SQL language standard, does not support transactions, but performance than SQL. Can be summed up: NoSQL data for high concurrent read and write, read and write huge amounts of data, highly scalable data scenario, but when necessary transaction support and complex relational queries, NoSQL is not as good a relational database.

NoSQL types of databases: a database cache (memcached, Redis): the latter covers almost the majority of the former function, compared to the former, the latter supported by the data in memory periodically persisted to disk.

  and. Redis support String. list, set, zset and hash value as the data type

         Document database (mongoDB): not

         Column database (Hbase): relational database (storage line: each row exists in the database as a unit) is different column-rank storage unit is used as a storage column

  In the database, it does have a benefit to facilitate data analysis.

 

Second, install Redis on Linux

  First installation package onto a Linux opt directory, you can use Xftp, it can also be installed after the vmtool Trolley. Then use tar -zxvf Redis ... tar.gz, decompress the file, unzip complete access to the file directory, then execute make command is invalid because gcc command is not required at this time, you can use yum, CentOS can also go to the image file rpm six files, but given inconsistent versions of the operating system, it is recommended to use yum gcc-c ++ instructions seem appropriate, but you have to Linux networking.

  After the deal dependencies, directory after entering Redis extracting the make command, if you do not deal with before dependencies, execute the make command error, make distclean executed first major clean up residual files before you make under the command. Make clean up after the execution of instructions. This completes the compilation of the installation package, and then input instructions to perform the installation make install.

  

  So where to go to install it?

  Linux will default to install the software in / usr / local / bin / directory, you can cd / usr / local / bin / and ll look. It is worth mentioning that all / usr / bin or / usr / local software under bin /, we can run in any directory.

  Directory consists of:

  

Third, the use Redis

  ①, start Redis

  Run: redis-server

  

  现在处在前台运行状态,没法操作,可以Ctrl+c退出后(他会跟你说bye bye...),去修改他的配置文件设置Redis为后台运行。

  创建一个Redis的工作目录:/myRedis,然后去安装目录下拷贝一份配置文件到此目录。修改daemonize no 改成yes,意味让服务在后台运行,然后执行 :redis-server  /myredis/redis.conf。

  

  ②、使用客户端、连接关闭数据库

   

  

  至于为什么Redis的默认端口号是6379,感兴趣的朋友可以去了解下(/坏笑.png)

  我们知道Mysql默认有4个库,而Redis默认有16个库,0~15:

  

  但是由于Redis这16个库要么都连得上要么都连不上和一些权限问题,并且一个库中不能访问别的库的内容,所以在企业中一般只用默认的0号库。

  ③、单线程的Redis和多路IO复用的Linux

  在刚接触多线程和锁机制时,我们知道当多个线程访问共享资源时,为了保证数据的安全性,通常会给共享资源上一把锁,当一个线程访问这个资源时,其他线程就无法访问这个资源,如果一个线程死锁,那么多线程就会阻塞。但是在Linux中,由于Linux存在多路IO复用,当单线程的Redis在CPU中运行时,CPU会高速切换Redis的任务对象,以达到看似多线程的工作效果。Windows是没有多路IO复用的,所以在一开始,我们就只基于Linux学习Redis。

  附:初次接触,如有错误,欢迎指正

Guess you like

Origin www.cnblogs.com/superlsj/p/11478465.html