search
HomeDatabaseMysql Tutorial[NOSQL] Redis介绍

Redis是Salvatore Sanfilippo在2009年为其初创公司LLOOGG开发的,目前仍是独立项目,但VMWare赞劣了项目(作者是其雇员)。它采用

Redis概述

Redis是Salvatore Sanfilippo在2009年为其初创公司LLOOGG开发的,目前仍是独立项目,但VMWare赞劣了项目(作者是其雇员)。它采用C语言实现,因此性能很好。采用BSD许可证,使用键值存储,和Amazon Dynamo,Cassandra,Riak,Voldemort,Memcache类似。支持丰富的数据类型,比如数组,链表,集合等,非常适合需要表达时间线的web服务,例如微博。

Ubuntu 14.04下Redis安装及简单测试

Redis集群明细文档

Ubuntu 12.10下安装Redis(图文详解)+ Jedis连接Redis

Redis系列-安装部署维护篇

CentOS 6.3安装Redis

Redis配置文件redis.conf 详解

Redis支持的数据类型有:

 

Redis的主从复制

Redis自带有主从复制的功能,只要设置配置文件redis.conf的slaveof选项即可,如下所示:

 

Redis的高可用

目前为止,Redis官方还在开发redis-cluster,可参考,中译版

但我们可以使用keepalived+redis的方法实现高可用,如下所示:

1. redis的配置
主机 端口 角色
redis0 6379 master
redis1 6379 slave

 

2. keepalived的配置
redis0和redis1使用一个虚拟ip

并使用如下脚本监控redis服务是否存活:

#!/bin/bash
/usr/local/bin/redis-cli -h 192.168.1.53 -p 6379 info > /dev/null
if [ $? -eq 0 ]; then
        echo "redis OK"
        exit 0
else
        echo "no redis service found!"
        /usr/local/bin/redis-server /path/to/redis.conf
        # try to start it again
        /usr/local/bin/redis-cli -h 192.168.11.53 -p 6380 info > /dev/null
        if [ $? -eq 0 ]; then
                exit 0
        else
                # restart failed
                killall keepalived
                echo "error"
        fi
fi

要实现redis的故障恢复,可以使用keepalived配置的notify_master, notify_backup这两个方法执行特有的脚本。实际上只要在slave(即redis1)上有2个脚本,第一个用于在redis1接管虚拟ip之后,执行slaveof no one把自己变成master。第二个是在redis1交出虚拟ip之后,在redis0执行slaveof no one确保redis0恢复为主的状态,并对redis1执行slaveof redis0 6379开始重新从master同步数据,如果自己已经是slave就没必要同步了。
redis1上keepalived的配置方法如下,redis0只要去掉notify_master, notify_backup两行即可。

! Configuration File for keepalived
global_defs {
router_id redis1
}
vrrp_script Monitor_Redis {
 script "/opt/redis_keepalive.sh"
 interval 10
 weight 2
}
vrrp_instance 360 {
 state BUCKUP #(主机为MASTER,备用机为BACKUP)
 interface eth0 #(HA监测网络接口)
 virtual_router_id 110 #(主、备机的virtual_router_id必须相同)
 mcast_src_ip 192.168.11.53 #(多播的源IP,设置为本机外网IP,与VIP同一网卡)此项可不设置
 priority 70 #(主、备机取不同的优先级,,主机值较大,备份机值较小,值越大优先级越高)
 advert_int 1 #(VRRP Multicast广播周期秒数)
 authentication {
  ......
}
 notify_master /opt/redis_2master.sh
 notify_backup /opt/redis_2backup.sh
 track_script {
 Monitor_Redis #(调用nginx进程检测脚本)
}
 virtual_ipaddress {
 192.168.11.4 #(VRRP HA虚拟地址)
 }
}

更多详情见请继续阅读下一页的精彩内容:

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL's Role: Databases in Web ApplicationsMySQL's Role: Databases in Web ApplicationsApr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

MySQL: Building Your First DatabaseMySQL: Building Your First DatabaseApr 17, 2025 am 12:22 AM

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL: A Beginner-Friendly Approach to Data StorageMySQL: A Beginner-Friendly Approach to Data StorageApr 17, 2025 am 12:21 AM

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

Is MySQL Beginner-Friendly? Assessing the Learning CurveIs MySQL Beginner-Friendly? Assessing the Learning CurveApr 17, 2025 am 12:19 AM

MySQL is suitable for beginners because: 1) easy to install and configure, 2) rich learning resources, 3) intuitive SQL syntax, 4) powerful tool support. Nevertheless, beginners need to overcome challenges such as database design, query optimization, security management, and data backup.

Is SQL a Programming Language? Clarifying the TerminologyIs SQL a Programming Language? Clarifying the TerminologyApr 17, 2025 am 12:17 AM

Yes,SQLisaprogramminglanguagespecializedfordatamanagement.1)It'sdeclarative,focusingonwhattoachieveratherthanhow.2)SQLisessentialforquerying,inserting,updating,anddeletingdatainrelationaldatabases.3)Whileuser-friendly,itrequiresoptimizationtoavoidper

Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Apr 16, 2025 am 12:20 AM

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL: Database Management System vs. Programming LanguageMySQL: Database Management System vs. Programming LanguageApr 16, 2025 am 12:19 AM

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL: Managing Data with SQL CommandsMySQL: Managing Data with SQL CommandsApr 16, 2025 am 12:19 AM

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment