Redis Open Source Cache database

Source: Internet
Author: User
Tags benchmark redis server

Tag: Base Ack object exists function vim master-slave shutdown only

   Redis is an open-source, high-performance key-value system that can be used to cache or store data. Redis data can be persisted and supported by a variety of data types: string, list, hash (hash), set (set), and ordered set (sorted set). Can be a good complement to the relational database. It also provides a variety of client python,ruby,erlang,php that can be easily invoked.

Persistence:

Redis is a memory database (similar to memcache), excellent in data access efficiency, and because of the risk of data loss in memory, Redis provides two persistence mechanisms to write in-memory data to disk in a timely manner.

The RDB uses storage snapshots to write memory data to disk periodically, semi-persistent

AOF writes to a AOF file on disk, using a log-like Binlog, each command that changes Redis data.

Redis turns on the RDB mode by default, turning off AOF mode because AOF is more resource-intensive, but it is very safe for data, called full persistence, which mode to choose on demand.

Master-Slave function:

To prevent Redis disk corruption, resulting in data loss, REDIS provides replication capabilities to automatically synchronize data from one primary database to the database to prevent data loss.

Master-Slave principle:

1. After starting the database, send the SYNC command to the primary database

2. After the master database receives the SYNC command, it starts to save the snapshot, during which all commands issued to the primary database are cached.

3. After the snapshot is saved, the primary database sends the snapshot and cached commands to the database

4. Save the snapshot files from the main data from the database and execute the cache commands from the primary database sequentially.

During synchronization, from the database is not blocked, it defaults to using the data before the synchronization to continue to respond to commands sent by the client

: https://code.google.com/p/ Redis /downloads/list

I. Installation of Redis

[Email protected] src]# tar zxf redis-2.6.10.tar.gz

[Email protected] src]# CD redis-2.6.10

[[email protected] redis-2.6.10]# make

[[email protected] redis-2.6.10]# make install

Second, adjust the Redis

[Email protected] ~]# Mkdir/usr/local/redis

[Email protected] ~]# CD!$

[email protected] redis]# CP. /src/redis-2.6.10/redis.conf.

[email protected] redis]# CP. /src/redis-2.6.10/src/redis-cli.

[email protected] redis]# CP. /src/redis-2.6.10/src/redis-server.

[email protected] redis]# CP. /src/redis-2.6.10/src/redis-sentinel.

[email protected] redis]# CP. /src/redis-2.6.10/src/redis-benchmark.

[email protected] redis]# CP. /src/redis-2.6.10/src/redis-check-aof.

[email protected] redis]# CP. /src/redis-2.6.10/src/redis-check-dump.

# # redis.conf Master configuration file

# # REDIS-CLI command Line Operations tool

# # Redis-server Startup program

# # Redis-sentinel Cluster management tools

# # Redis-benchmark Performance test Tool to test the read and write performance of Redis under current system configuration

# # redis-check-aof Update log check,--fix can repair log file

# # Redis-check-dump checking local data files

Third, editor redis.conf

[Email protected] redis]# MV redis.conf Redis.conf.bak

[Email protected] redis]# vim redis.conf

Daemonize Yes

# # starts with daemon mode

Pidfile/usr/local/redis/logs/redis.pid

# # define PID file storage path

Port 6379

# # Listening Port

Timeout 300

# # Request Time-out

LogLevel Debug

# # define Log levels

Logfile/usr/local/redis/logs/redis.log

# # defines the log file path

Databases 16

# # Start the number of DB instances, the default connection database is 0, you can connect to different databases by select N

Save 900 1

Save 300 10

Save 60 10000

# # Policy for saving data to disk from memory

# # when there are 1 keys data changes, 900 seconds to disk once

# # When there are 10 keys data changes, 300 seconds to disk once

# # When there are 1W keys data changes, 60 seconds to disk once

Rdbcompression Yes

# # when dump. Rdb database, whether to compress data objects

Dbfilename Dump.rdb

# # DUMP DATABASE, the file name saved by the database

dir/usr/local/redis/data/

# # Dump when the database saved the path

#-----------------------------------------------------------------------------------------------------

AppendOnly No

# # Whether to turn on the log function, if you turn on each operation will record a log, equivalent to MySQL binlog, but will affect the efficiency

#appendfilename appendonly.aof

# # AOF file name, default is Ppendonly.aof

#appendfsync everysec

# # Sync data to disk rules,

# # No does not actively write to the disk, relying on the system to write, generally 30 seconds or so write once, the best performance, but there is no guarantee of persistence.

# # Everysec is forced to write to disk once per second, in terms of performance and persistence compromise, recommended to use.

# # Always force writes to disk every time a write is received, is the most guaranteed full persistence, but slow.

#no-appendfsync-on-rewrite Yes

# # in the log rewrite, do not do command append operation, but just put it in the buffer, to avoid the append to the command caused by disk IO conflict

#auto-aof-rewrite-percentage 100

# # The size of the current AOF file is twice times the size of the AOF file that was last log rewrite, and the new log rewrite process starts automatically

#auto-aof-rewrite-min-size 64MB

# # Current AOF file starts the minimum value of the new log rewrite process, avoiding frequent rewriting due to small file size when starting Redis

#-----------------------------------------------------------------------------------------------------

Four, start Redis

[Email protected] ~]# echo "vm.overcommit_memory = 1" >>/etc/sysctl.conf

[Email protected] ~]# sysctl Vm.overcommit_memory=1

# # Adjust kernel parameters, if you do not adjust Redis will report a warning message

[[email protected] ~]# Mkdir/usr/local/redis/data # Create the Data directory

[[email protected] ~]# Mkdir/usr/local/redis/logs # Create logs Directory

[[email protected] ~]# redis-server/usr/local/redis/redis.conf # boot Redis, you need to specify a profile path

[Email protected] ~]# NETSTAT-ANPT | grep Redis

TCP 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 1176/redis-server

V. Test Redis

-----------------------------------------------------------------------------------------------------

[Email protected] ~]# REDIS-CLI

Redis 127.0.0.1:6379> Set Password 123

Ok

Redis 127.0.0.1:6379> Get password

"123"

Redis 127.0.0.1:6379> quit

# # Log on to native Redis, write keys/value, read keys

[Email protected] ~]# ls/usr/local/redis/data/

# # No DUMP.RDB generated because the semi-persisted save rule did not trigger

[Email protected] ~]# REDIS-CLI shutdown

[Email protected] ~]# ls/usr/local/redis/data/

Dump.rdb

# # When Redis is turned off, the in-memory data is saved as Dump.rdb

[Email protected] ~]# redis-server/usr/local/redis/redis.conf

[Email protected] ~]# REDIS-CLI

Redis 127.0.0.1:6379> Get password

"123"

Redis 127.0.0.1:6379> quit

# # After Redis starts reading data from the Dump.rdb file, the data still exists

-----------------------------------------------------------------------------------------------------

[Email protected] ~]# rm-rf/usr/local/redis/data/*

[Email protected] ~]# REDIS-CLI

Redis 127.0.0.1:6379> Set Password abcdef

Ok

Redis 127.0.0.1:6379> Get password

"ABCdef"

Redis 127.0.0.1:6379> quit

[Email protected] ~]# kill-9 ' cat/usr/local/redis/logs/redis.pid '

# # When Redis is not turned off normally, such as kill-9, Redis server sudden outage, etc.

[Email protected] ~]# ls/usr/local/redis/data/

# # is not synchronizing the in-memory data to disk, which means that the Dump.rdb file is not generated

[Email protected] ~]# redis-server/usr/local/redis/redis.conf

[Email protected] ~]# REDIS-CLI

Redis 127.0.0.1:6379> Get password

(nil)

Redis 127.0.0.1:6379> quit

# # Then start Redis and find the data is missing. If you can't tolerate this loss you can start AOF full persistence .


Redis Open Source Cache database

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.