Redis development and operation and maintenance reading notes 2

Chapter 1 Getting to Know Redis

8 Important Features of Redis
  • Fast speed: RW speed is about 100,000/second, data is stored in memory, C language design, single-threaded architecture, to avoid thread contention,
  • Key-value pair-based data structure server: The full name of Redis is REmote DIctionary Server, which mainly provides 5 data structures - string, hash, list, set, ordered set, and evolved from the string to the structure of bitmap and HyperLogLog , and with the development of LBS, the GEO (geographic information positioning) function has been introduced since 3.2
  • Rich functions: realize caching through key expiration function, realize message system through publish and subscribe function, support Lua script to create new Redis commands, provide simple transaction function to ensure transaction characteristics, and provide pipeline function to realize that the client transmits a batch of commands at a time, reducing network overhead
  • Simple and stable: the source code is small, the earlier version has only 20,000 lines, and the cluster feature added in 3.0 has only 50,000 lines of code; the single-threaded model also makes the server-side processing model simple and easy for client-side development; no need to rely on operating system class libraries for implementation Transaction processing
  • Multiple client languages: access clients in various languages ​​through TCP
  • Persistence: RDB and AOF two persistence strategies
  • Master-slave replication: one master and multiple slaves
  • High availability and distribution: Redis 2.8 provides Sentinel high availability implementation to ensure fault detection and automatic transfer of faulty nodes. 3.0 began to provide cluster and distributed implementation of Redis Cluster, providing high availability, read-write and capacity expansion

Application scenarios suitable for Redis
  • Cache: key value expiration time setting, flexible maximum memory setting and elimination strategy after memory overflow
  • Leaderboard
  • Counters: natively supported and perform well
  • Social network: support like/dislike, fans, common friends/likes, push, pull-down innovation
  • message queue

Application scenarios that Redis is not suitable for
  • Not suitable for cooling data

Redis installation - Linux
can be installed through yum/apt or source code. Considering that Redis is easy to install and update quickly, source code installation is recommended
wget http://download.redis.io/releases/redis-3.xxtar.gz (you can download the latest stable version)
tar xzf redis-3.x.x.tar.gz
ln -s redis-3.x.x redis
cd redis
make
make install

A soft link of redis is established here. The purpose is to reduce the application's dependency on the version in future upgrades.
Make install can install redis in the /usr/local/bin directory, and execute redis commands in any directory, such as redis-cli -v You can view
the configuration, startup, operation and shutdown of the
Redis executable file instructions for the redis version of Redis
  • redis-server: start redis
  • redis-cli: redis command line client
  • redis-benchmark: redis benchmarking tool
  • redis-check-aof: AOF persistent file detection and repair tool
  • redis-check-dump: RDB persistent file detection and repair tool
  • redis-sentinel: start Redis Sentinel


Redis should be started with a configuration file, or by specifying a port number and configuration name and value
redis-server --configKey configValue1 --configKey2 configValue2 --port Port


redis-server /opt/redis/redis.conf


There are more than 60 configurations in redis.conf. The basic configuration is as follows:
  • port: port
  • logfile: log file
  • dir: working directory (stores persistent files and log files)
  • daemonize: whether to start Redis in daemon mode

redis-cli can connect to the Redis server in two ways:
  • redis-cli -h {ip} -p {port}, then interact
  • redis-cli -h {ip} -p {port} {command} interact directly

When there is no -h parameter, the default connection is 127.0.0.1. If there is no -p parameter, the default connection is 6379 port.

Terminate the redis service:
redis-cli shutdown

This is an elegant closing method, which will disconnect all connections between the server and the client, and generate persistent files. If you use kill -9 to forcibly kill the process, the files will not be persistent, and the buffer resources will not be closed gracefully. , causing AOF and replication to lose data.
shutdown can enter a parameter, indicating whether to generate a persistent file before shutting down redis
redis-cli shutdown nosave|save


The version number of Redis is the same as that of Linux. If the second digit of the version number is an odd number, it is an unstable version, and an even number is a stable version . The production environment should use an even-numbered version.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326264087&siteId=291194637