Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic use of redis

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Introduction to 1.redis persistence

A.remote dictionary server

b. It is also the storage of key values based on key-value.

C.redis supports a wealth of data types

d. Persistent caching service

e. Support master-slave synchronization (master-slave synchronization)

Characteristics of 2.redis

a. High performance: redis can support frequent read and write over 100k per second

b. Rich data types: redis supports binary strings lists hashes sets, etc.

c. Atomicity: all operations of redis are atomic, and redis also supports full union of several operations

Atomic execution after

d. Rich features: redis supports publish/subscribe.

E.redis supports heterogeneous master-slave replication.

f. Data can be stored persistently

3. Data type

A.String

B.Hash

C.List

D.Set

E.Sorted set

4.redis application scenario description (*)

A.mysql needs to constantly disassemble libraries and tables, and memcached also needs to continue to expand, expand and maintain.

A lot of time for development, operation and maintenance

The problem of data consistency between b.memcached and mysql databases is an age-old problem.

The low hit rate of c.memcached will increase the pressure on access to the back-end database.

The best scene of redis

The best trial scenario for 1.redis is all data in-memory.

2.redis is used as a substitute for memcache

3. When you need more data type support, you can use redis

4. Use redis when the stored data cannot be deleted

5. Scenarios where load balancing is required (redis master-slave synchronization)

Installation and 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 # specify the path make PREFIX= during installation

c. Add link

Ln-s / application/redis-2.8.9 / application/redis

Directory structure and files of 6.redis

d. View directory structure

Tree / application/redis-2.8.9/bin

Description of files under the e.bin directory

Redis-server: daemon launcher for Redis server

Redis-cli: Redis command line operation tool. Of course, you can also use telnet to operate according to the plain text protocol.

Redis-benchmark Redis performance testing tool to test the read and write performance of Redis under system and configuration

Redis-check-aof: update log check

Redis-check-dump: for local data checking

7. Start redis

a. Configure the environment variables for redis

Echo 'export PATH=/application/redis/bin:$PATH' > > / etc/profile

Source / etc/profile

b. Create a directory of configuration files for redis

Mkdir-p / application/redis/conf/

Cp-apr (redis decompression 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.overcommit_memory=1' for this to 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 &

How to shut down d.redis correctly

Redis-cli shutdown

8. Start the redis service and test redis using client commands

a. Connect to redis (redis-cli-- help to view basic usage)

Redis-cli-h 127.0.0.1

b. Do not log in to create

Redis-cli-h 127.0.0.1-p 6379 set 001 jiahb

Login in c.telnet mode

Telnet 127.0.0.1 6379

Introduction to 9.redis multiple data types

D

Php client extension installation for 10.redis

a. Download the source code

Wget https://github.com/nicolasff/phpredis/archive/master.zip

b. Decompression

Tar xf phpredis2.2.4 # decompression

Cd phpredis2.2.4 # switch directories

/ application/php5.3.27/bin/phpize

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

Make & & make install # compile and install the 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 extension to redis is installed properly.

Introduction of 11.redis configuration file and master-slave synchronization configuration

a. View configuration fil

Vim / application/redis/conf/redis.conf

b. Key parameters

Port 6379 listening port

Tcp-keeplive 40 session persistence

Loglevel warnning log level

Databases 16 sets the number of databases

If there is a key change in save 9001,900 seconds, save it.

If there is a key change in save 300s, save it.

Configuration 9 for slaveof master-slave replication

twelve。 Monitoring redis database writes

1.redis-cli-h 127.0.0.1-p 6379 monitor monitors redis database writes and changes

2.redis-cli-h 127.0.0.1-p 6379 info # View the status information of redis

3.redis-cli-h 127.0.0.1-p 6379 info Replication # View redis master-slave replication

Application of 13.Redis load balancing

1.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report