Redis non-Relational Database Service (Nosql)

Source: Internet
Author: User
Tags redis cluster redis server

Redis non-Relational Database Service (Nosql)

Introduction:

Redis is an open-source, high-performance key-value system that can be used to cache or store data.

Redis data can be persistent and supports multiple data types: string, list, hash, set, and sorted set ).

It can complement relational databases. It also provides a variety of clients such as Python, Ruby, Erlang, and PHP for convenient calls.

Persistence:

Redis is a memory database (similar to memcache) and has excellent data access efficiency. Because data in the memory is at risk of data loss at all times, Redis provides two persistence mechanisms, write Data in the memory to the disk in a timely manner.

RDB regularly writes memory data to disks using snapshot storage for semi-persistence.

AOF uses the log Writing Method (similar to mysql binlog). Every time you execute a command to change Redis data, it is written to an aof file on the disk.

By default, apsaradb for Redis enables the RDB mode and disables the AOF mode. Because AOF is more resource-consuming, but highly secure for data, it is called full persistence. Which mode is needed.

Master/Slave features:

To prevent data loss caused by Redis disk damage, Redis provides the replication function to automatically synchronize data from a primary database to the slave database to prevent data loss.

Master-slave principle:

1. After starting the database, send the SYNC command to the primary database.
2. After receiving the SYNC command, the master database starts to save the snapshot. During this period, all commands sent to the master database are cached.
3. After the snapshots are saved, the master database sends the snapshots and cache commands together to the slave database.
4. Save the snapshot files sent from the master data from the database and execute the cache commands sent from the master database in sequence.

In the synchronization process, the slave database will not be blocked. By default, it uses the data before synchronization to continue responding to commands sent from the client.

: Https://code.google.com/p/redis/downloads/list

1. Install Redis

shell > tar zxf redis-2.6.10.tar.gzshell > cd redis-2.6.10; make; make install

Ii. Adjust Redis

shell > mkdir /usr/local/redisshell > cd !$shell > cp ../src/redis-2.6.10/redis.conf .shell > cp ../src/redis-2.6.10/src/redis-cli .shell > cp ../src/redis-2.6.10/src/redis-server .shell > cp ../src/redis-2.6.10/src/redis-sentinel .shell > cp ../src/redis-2.6.10/src/redis-benchmark .shell > cp ../src/redis-2.6.10/src/redis-check-aof .shell > cp ../src/redis-2.6.10/src/redis-check-dump .

# Redis. conf main configuration file
# Redis-cli command line tool
# Redis-server startup program
# Redis-sentinel cluster management tool
# Redis-benchmark performance testing tool to test redis's read/write performance in the current system configuration
# Redis-check-aof Update log check, -- fix can repair log files
# Redis-check-dump check local data files

3. Edit redis. conf

Shell> mv redis. conf redis. conf. bakshell> vim redis. conf
Daemonize yes # Start pidfile/usr/local/redis/logs/redis as a daemon. pid # define the pid file storage path port 6379 # listening port timeout 300 # request timeout loglevel debug # define the Log Level logfile/usr/local/redis/logs/redis. log # define the log file path databases 16 # Number of database instances started. The default database connection value is 0. You can use select N to connect to different databases.
# Policy for saving data from memory to disk:
Save 900 1 # When one keys data refresh to the disk in 900 seconds
Save 300 10 # When 10 keys data changes, refresh to the disk once every 300 seconds
Save 60 10000 # refresh to the disk once every 60 seconds when one million keys data changes
Rdbcompression yes # Whether to compress data objects in the dump. rdb Database
Dbfilename dump. rdb # name of the file stored in the database during dump
Dir/usr/local/redis/data/# path in which the database is saved During dump
# Renewal #-----------------------------------------------------------------------------------------------------Appendonly no # Whether to enable the log function. If you enable this function, a log is recorded, which is equivalent to the binlog of mysql, but affects the efficiency # appendfilename appendonly. aof # AOF file name. The default value is ppendonly. aof # appendfsync everysec # rules for synchronizing data to the disk: #1. no is not actively written to the disk. the dependency and system write are generally written once every 30 seconds. The best performance is achieved, however, persistence is not guaranteed. #2. everysec forcibly writes data to the disk once per second, which compromises the performance and persistence. We recommend that you use it. #3. Every time always receives a write operation, it is immediately forced to write data to the disk. It is the most guaranteed full persistence, but the speed is slow. # No-appendfsync-on-rewrite yes # When the log is overwritten, The APPEND Command is not executed, but is only placed in the buffer zone, avoid conflicts with command appending on disk I/o # auto-aof-rewrite-percentage 100 # When the current AOF file size is twice the size of the AOF file obtained from the previous log rewriting, automatically start the new log rewriting process # auto-aof-rewrite-min-size 64 mb # minimum value of the new log rewriting process started by the current AOF file, avoid frequent rewriting due to small files when starting redis# Renewal #-----------------------------------------------------------------------------------------------------
# Set whether to combine a small package into a package for sending a response to the client

4. Start Redis

shell > echo "vm.overcommit_memory = 1" >> /etc/sysctl.confshell > sysctl vm.overcommit_memory=1

# Adjust the kernel parameters. If you do not adjust redis, a warning is reported.

Shell> mkdir/usr/local/redis/data # create a data directory shell> mkdir/usr/local/redis/logs # create a logs directory shell> redis-server/usr/local/ redis/redis. conf # When starting redis, You need to specify the configuration file path shell> netstat-anpt | grep redistcp 0 0 0.0.0.0: 6379 0.0.0.0: * LISTEN 1176/redis-server

V. Test Redis

Bytes -----------------------------------------------------------------------------------------------------

shell > redis-cliredis 127.0.0.1:6379> set password 123OKredis 127.0.0.1:6379> get password"123"redis 127.0.0.1:6379> quit

# Log on to the local redis instance, write keys/value, and read keys

shell > ls /usr/local/redis/data/

# Dump. rdb is not generated because the semi-persistent save rule is not triggered.

shell > redis-cli shutdownshell > ls /usr/local/redis/data/dump.rdb

# When redis is disabled, data in the memory will be saved as dump. rdb

shell > redis-server /usr/local/redis/redis.confshell > redis-cliredis 127.0.0.1:6379> get password"123"redis 127.0.0.1:6379> quit

# After redis is started, it reads data from the dump. rdb file, so the data still exists

Bytes -----------------------------------------------------------------------------------------------------

shell > rm -rf /usr/local/redis/data/*shell > redis-cliredis 127.0.0.1:6379> set password abcdefOKredis 127.0.0.1:6379> get password"abcdef"redis 127.0.0.1:6379> quitshell > kill -9 `cat /usr/local/redis/logs/redis.pid`

# When redis is not shut down normally, such as kill-9 and the redis server suddenly goes down

shell > ls /usr/local/redis/data/

# The data in the memory will not be synchronized to the disk, that is, the dump. rdb file will not be generated

shell > redis-server /usr/local/redis/redis.confshell > redis-cliredis 127.0.0.1:6379> get password(nil)redis 127.0.0.1:6379> quit

# Start redis and find data loss. If you cannot tolerate this loss, you can start AOF full persistence.

You may also like the following articles about Redis. For details, refer:

Install and test Redis in Ubuntu 14.04

Basic configuration of Redis master-slave Replication

Redis cluster details

Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis

Redis series-installation, deployment, and maintenance

Install Redis in CentOS 6.3

Learning notes on Redis installation and deployment

Redis. conf

Redis details: click here
Redis: click here

This article permanently updates the link address:

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.