Redis Learning Notes (simple to understand and run)

Source: Internet
Author: User
Tags redis server

Redis Learning Notes (simple to understand and run)

An open source non-relational database is an abbreviation for Remote Dictionary server, which stores data in a dictionary structure

Allows other apps to read and write content from the dictionary through the TCP protocol.

Redis supports stored key-value data types
    • String type
    • Hash type
    • List type
    • Collection type
    • Ordered collection types
Redis features a look at the storage differences between MySQL and Redis

For example:

(存储一篇文章,文章包括:标题(title),正文(content),阅读量(views),标签(tags))

Demand:

把数据存储在数据库中,并且可以通过标签检索出文章

Relational database implementations:

把标题,正文,阅读量 存储在一个表中(文章表)标签存储在一个表中(标签表)通过第三个表对应表(对应表)缺点:查询时需要把3个表进行连接,不是很直观

Redis implementations:

post{"title"} = "Hello World!"post{"content"} = "我是文章 , 我是文章"post{"views"} = 0post{"tags"} = {"Java","Redis"}优点:可以将程序中的数据直接映射到Redis中,数据在Redis中的存储方式和在程序中的存储方式很相近.对不同的数据类型提供了方便的操作方式
Memory Storage and persistence
Redis数据库中的数据都存储在内存中.内存的读取速度快于硬盘读取,所以Redis在性能对比上于基于硬盘读取的数据库有明显的优势将数据存储在内存中也会出现问题,程序退出后,内存中的数据就会丢失不过可以使用Redis的持久化技术来解决,可以将数据异步写入到硬盘中,而且不会影响继续提供服务.
Other features
Redis还可以用做缓存,队列系统等Redis可以为每个键设置生存时间(Time to Live ,TTL),生存时间到了键会自动被删除.这一功能Redis可以作为缓存系统来使用.作为缓存系统,Redis还可以限定内存最大占用空间,当数据到达最大限定值时,Redis可以按照规则淘汰不需要的键.Redis的列表类型可以用来实现队列.支持阻塞读取,可以实现一个高性能的优先级队列. 更高层面上,Redis还支持"订阅/发布"的消息模式,可以基于此构建聊天室等系统.
Simple and stable
Redis提供了一百多个命令Redis提供了不同语言的客户端库
Installing Redis
Redis兼容大部分系统,Linux Windows  OS X 等一般都是在Linux服务器上安装,记录在Linux上安装的过程下载、提取和编译:$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz$ tar xzf redis-3.0.7.tar.gz$ cd redis-3.0.7$ make实际运行redis前可以使用make test来测试Redis是否编译正确
Redis executable File Description
文件名                     说明redis-server                Redis服务器redis-cli               Redis命令行客户端redis-benchmark         Redis性能测试工具redis-check-aof         AOF文件修复工具redis-check-dump            RDB文件检查工具常用的是redis-server和redis-cli.启动redis使用的就是redis-server,  redis-cli是命令行客户端
Start Redis
There are two ways to start: 1. Direct start: Direct running redis-server redis Server default port is 6379 port, can customize interface: Redis-server--port 63            70 2. Start with init script through init script, this method is used by the production environment to enable Redis to start with the system startup. In the Untils folder of the Redis source code directory, there is a redis_init_script initialization script that needs to configure how Redis runs and persistent files, where the log files are stored, and so on: (1) Configuring the initialization Pin This, copy the initialization script to the/ETC/INIT.D directory, the file name is the Redis_ port number, and then modify the value of the Redissport variable in line 6th of the script to the same port number (2) to create the required folder/etc /redis the configuration file that holds the Redis/var/redis/the port number to hold the Redis persistence file (3) modify the configuration file. First copy the profile template (under the root directory) to the/ETC/R                        Edis folder, name the port number (such as 6370.conf), and then edit the Enable configuration file by passing the path of the configuration file as a startup parameter to Redis-server at startup, such as: Redis-server/path/to/redis.conf passing a configuration option with the same name through a startup parameter overrides the corresponding parameter in the configuration file: Redis-server/pa th/to/redis.conf--loglevel warning Redis can also dynamically modify configuration files at run Time: config SET loglevel wa                     Rning can also get the current configuration of Redis   Config GET loglevel configuration file parameters: parameter values        Description Daemonize Yes runs in daemon mode pidfile                          /var/run/redis_ port number. pid file location of PID Redis Port port number Set the port number of the Redis dir/var/redis/port number Set Persistent folder location using/etc/init.do/re Dis_ Port number Start Redis

If not, you will need to copy the Redis-server and REDIS-CLI under SRC to/usr/local/bin to execute: sudo update-rc.d redis_ port number default can be started with the system

Client Connection Redis-cli-h host address-P Redis Port
Stop Redis
考虑到持久化,强制关闭Redis可能会丢失数据,所以正确停止Redis的方法为redis-cli SHUTDOWN当redis收到SHUTDOWN命令后,会先断开所有的客户端连接,然后根据配置执行持久化,最后完成退出也可以使用 kill redis的进程PID 关闭redis

Redis Learning Notes (easy to learn and run)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.