Redis Basic Usage

Source: Internet
Author: User
Tags redis server

1.redis Persistence Introduction
A.remote Dictionary Server

B. Also storage based on Key-value key values

C.redis support for richer data types

D. Persistent Cache service,

E. Support for Master-slave synchronization (master-Slave synchronization)

2.redis Features
A. High performance: Redis supports read and write more than 100k per second
B. Rich data types: Redis supports binary strings lists hashes sets, etc.
C. atomicity: All Redis operations are atomic, and Redis supports several operations
After the atomicity of the execution
D. Rich features: Redis supports Publish/subscribe.

E.redis supports master-slave replication of different machines

F. Storage of data can be persisted

3. Data type

A.string
B.hash
C.list
D.set
E.sorted Set

4.redis Application Scenario Description (*)

A.mysql need to constantly dismantle the table, memcached also need to continue to follow the expansion, expansion and maintenance work occupy
Extensive devops time

The b.memcached and MySQL database data consistency problem is a chronic

C.memcached hit rate is low, resulting in increased access pressure to the backend database.

The best scenario for Redis

1.redis Best trial scenario is all data in-memory
2.redis used as a substitute for memcache
3. When more data type support is required, you can use the Redis
4. When the stored data cannot be excluded, use Redis
5. Scenarios requiring load balancing (Redis master-Slave synchronization)

Installation deployment of 5.redis
A. Download the source package

wget http://download.redis.io/releases/redis-2-8-9.tar.gz

Tar XF redis-2-8-9.tar.gz

CD redis-2-8-9

B. Compile and install (no configure required)

Less README

Make Malloc=jemalloc

Make prefix=/application/redis-2.8.9 install #在安装时指定路径 make prefix=



C. Add Link
Ln-s/application/redis-2.8.9/application/redis

6.redis directory structure and files
D. View the directory structure

Tree/application/redis-2.8.9/bin

Document description in the E.bin directory

Redis-server:redis Server Daemon Startup program
Redis-cli:redis Command Line operation Tool, of course, you can also use Telnet according to the Plain Text protocol operation
Redis-benchmark Redis Performance Testing tool to test Redis's read and write performance in system and configuration

Redis-check-aof: Update log check

Redis-check-dump: for local data checking
7. Start Redis

A. Configuring the environment variables for Redis

Echo ' Export path=/application/redis/bin: $PATH ' >>/etc/profile
Source/etc/profile
B. Creating a configuration file directory for Redis

Mkdir-p/application/redis/conf/

CP-APR (Redis's extract directory) redis.conf/application/redis/conf/

C. Start Redis (redis-server)

Redis-server/application/redis/conf/redis.conf &

WARNING Overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ' vm.overcommit_memory = 1 ' to/etc/sysctl.conf and then reboot or run the command ' Sysctl vm.overcom Mit_memory=1 ' for the take effect. (This error may be reported)

Solution: Echo ' vm.overcommit_memory ' >>/etc/sysctl.conf
Sysctl Vm.overcommit_memory=1

Redis-server/application/redis/conf/redis.conf &

D.redis correct shutdown method

REDIS-CLI shutdown

8. Start Redis Service and test Redis with client commands

A. Connect to Redis (redis-cli--help View basic usage)

Redis-cli-h 127.0.0.1

B. Create without Login
Redis-cli-h 127.0.0.1-p 6379 Set 001 JIAHB

C.telnet Mode Login
Telnet 127.0.0.1 6379

9.redis Multi-Data type introduction
D

10.redis PHP Client Extension installation
A. Download the source code
wget Https://github.com/nicolasff/phpredis/archive/master.zip
B. Unzip

Tar XF phpredis2.2.4 #解压

CD phpredis2.2.4 #切换目录

/application/php5.3.27/bin/phpize

./configure--with-php-config=/application/php/bin/php-config

Make && do install #编译并安装redis. so file

C. Modify php.ini settings and restart PHP

echo "Extension_dir =/application/php/lib/php/extensions/no". /"
echo "extension = redis.so" >>/application/php/lib/php.ini

Session.save_path = "tcp://ip:6379"



Pkill PHP-FPM
-
/application/php/sbin/php-fpm

HTTP://IP:8080 can see if the Redis extension is installed properly.


11.redis configuration file Introduction and master-Slave synchronization configuration

A. Viewing the configuration file

Vim/application/redis/conf/redis.conf

B. Key parameters
Port 6379 Listening ports
Tcp-keeplive 40 Session hold
LogLevel warnning Log Level
Databases 16 Setting the number of databases
Save 900 1 900 seconds has a key change, then saves
Save 300 10 300 seconds has a key change, then saves

Slaveof <masterip> <masterport> configuration of Master-slave replication 9


12. Monitoring Redis Database writes

1.redis-cli-h 127.0.0.1-p 6379 Monitor writes and changes to the Redis database

2.redis-cli-h 127.0.0.1-p 6379 Info #查看redis的状态信息

3.redis-cli-h 127.0.0.1-p 6379 Info Replication #查看redis主从复制情况

13.Redis Load Balancing applications

1.






Redis Basic Usage

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.