This is the 12th day of my participation in the August Text Challenge.More challenges in August

Redis introduction to Supergod – 01 Redis introduction and installation

Redis Entry to Supergod – 02 Why does Redis default 16 databases

Redis – 03 Redis. Conf configuration file details

Redis introduction to Supergod – 04 Redis 5 data structures


1k => 1000 bytes

1kb => 1024 bytes 1m => 1000000 bytes 1mb => 10241024 bytes 1g => 1000000000 bytes 1gb => 10241024*1024 bytes

The default Redis configuration file is redis.conf.

If we connect to Redis through the client, we can view or set the configuration items through the CONFIG command. The command to view configuration items is CONFIG GET CONFIG_SETTING_NAME.

Check the port number configuration item
127.0.0.1:6379> CONFIG GET port
1) "port"
2) "6379"
Check the password configuration item
127.0.0.1:6379> CONFIG GET requirepass
1) "requirepass"
2) "123456"127.0.0.1:6379 >Copy the code

Of course, you can also view all configuration items through CONFIG GET *. Only some configuration items are listed here.

127.0.0.1:6379> CONFIG GET *
  1) "dbfilename"
  2) "dump.rdb"
  3) "requirepass"
  4) "123456"
  5) "masterauth"
  6) ""
  7) "cluster-announce-ip"
  8) ""
  9) "unixsocket"
 10) ""
 11) "logfile"
 12) ""
 13) "pidfile"
 14) "/var/run/redis_6379.pid"
 15) "slave-announce-ip"
 16) ""
 17) "replica-announce-ip"
 18) ""
 19) "maxmemory"
 20) "0"
 21) "proto-max-bulk-len"
 22) "536870912"
 23) "client-query-buffer-limit"
 24) "1073741824"
 25) "maxmemory-samples"
 26) "5".Copy the code

The CONFIG SET command modifies the configuration item in the syntax of CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE

# Change the log level127.0.0.1:6379 > CONFIG SET loglevel"notice"
OK
Copy the code

However, we usually open the redis. Conf configuration file, make changes, and then restart the Redis service.



# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # INCLUDES # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

If you have more than one configuration file, you can import it in this configuration.
Import additional configuration files. If you have multiple Redis services that have common configuration items, you can write these common configuration items into a common.conf configuration file.
These redis services then include the configuration file, and their own configuration items are written in their own configuration files.
#
# include /path/to/local.conf
# include /path/to/other.conf


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # MODULES module # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

If we need to load other modules, we can configure it here
#
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # NETWORK NETWORK # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Bind 127.0.0.1 will only listen for requests from native clients. If bind 127.0.0.1 is configured, it will only listen for requests from all IP addresses.
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1: : 1
# bind 127.0.0.1


# are explicitly listed using the "bind" directive.
# Whether to enable the protected mode. By default, the protected mode is enabled. If bind and password are not specified in the configuration. If this parameter is enabled, redis can only be accessed locally.
Bind can be enabled if password and bind are enabled. Otherwise, disable it, that is, set it to no.
#
protected-mode no


Set the listening port number to 6379 by default. If set to 0, no TCP requests are listened on.
#
port 6379


You may need to set a higher value for high concurrency and slow client connections. This value represents the length of the completed queue (after completing the three-way handshake) in the TCP connection,
# this value must be under the Linux/proc/sys/net/core/somaxconn file value restrictions, redis default is 511, and Linux the default parameter value is 128.
# So we need to increase the size of both values to get better performance and desired results. It is usually changed to 2048 or larger.
Somaxconn = 2048 in /etc/sysctl.conf, then run sysctl -p in terminal
#
tcp-backlog 511


Redis supports listening on local connections.
# unixsocket /tmp/redis.sock
Configure file permissions on Unix sockets.
# unixsocketperm 700


If the timeout value is 0, the server will not be disconnected. The value cannot be less than 0
timeout 0


TCP keepalive. The units are seconds. If the value is not set to 0, the SO_KEEPALIVE value for configuring TCP is used.
There are two benefits to using Keepalive:
# 1. Detect the failed peer.
# 2. Reduce the problem that the network appears to be connected but is already connected to the peer end when the intermediate device has a problem.
In the Linux kernel, when keepalive is set, Redis will periodically send ack to the peer. Double the setting value is required when peer shutdown is detected

tcp-keepalive 300

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # GENERAL basic # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Yes indicates whether to run in the background. If the background allows, the service PID will be written to the /var/run/redis.pid file
daemonize yes


The Redis daemons can be managed by upstart and Systemd, depending on the operating system.
supervised no

The location of the file pid writes to when the redis service is started in the background
pidfile /var/run/redis_6379.pid


# Log level.
# debug: Logs a large amount of information, suitable for development and testing
# verbose: contains more log information
# notice: Indicates a proper amount of log information. This parameter is applicable to production environments
# Warning: Only some important and critical information will be recorded
loglevel notice


# The location of the log file, when specified as an empty string, is standard output. If redis is running in daemon mode, the log will be printed to /dev/null
logfile ""


Whether to record logs to system logs
# syslog-enabled no


Set the id of the system log
# syslog-ident redis


The syslog device must be user or local0 to local7
# syslog-facility local0


Set the number of databases. The default database is DB 0. You can select a different database on each connection using the select 
      
        command. Dbid is a number between 0 and databases - 1.
      
databases 16


Display log when interactive terminal starts
always-show-logo yes

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # SNAPSHOTTING snapshot # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Save data to disk. The format is: save 
       
       
        , that is, save once if at least changes keys have changed after seconds.
       
      
# if you don't want to save data to disk, comment out all save lines.
#
# save ""

save 900 1
save 300 10
save 60 10000


# by default, redis will stop accepting writes if the last background save fails. This is a strong way to let the user know that data cannot be persisted to disk correctly.
# Otherwise no one will notice the disaster. Redis will also automatically allow write operations if the background save process restarts.
# However, if you have a reliable monitor installed and you don't want Redis to do this, you can change it to No.
#
stop-writes-on-bgsave-error yes


# whether to compress strings in dump. RDB, default is yes. If you want to save some CPU resources, you can set it to no so that the data set may be large.
rdbcompression yes


If CRC64 validates RDB files, there is a performance penalty (about 10%).
rdbchecksum yes


# RDB file name.
dbfilename dump.rdb


# Database directory. It must be a directory to which aOF files will also be saved. By default, it is stored in the same directory as the startup script.
dir ./

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # the REPLICATION master-slave REPLICATION # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# Set the local host to slave and enter the IP address and port number of the master node
#
# replicaof <masterip> <masterport>


Master password. If password protection is enabled for the master service, the slave service requires a password to connect to the master.
#
# masterauth <master-password>


When a slave loses contact with the master, or when replication is in progress, the slave responds to the request in two ways:
# 1: If set to yes (the default), slave will still respond to client requests, but the data returned may be stale or may be empty at the time of the first synchronization;
# 2: If set to no, only info and replicaOF and AUTH.. The slave returns a "SYNC with master in progress" error.
#
replica-serve-stale-data yes


Set slave to read-only. Since version 2.6, slave is read-only by default.
#
replica-read-only yes

# Whether to use the diskless replication function for primary and secondary data replication.
#
repl-diskless-sync no


When 5 disks replication is enabled, wait 5 seconds before starting replication. Because more replicas need to reconnect, you can share one RDB. It can be set to 0 if the wait is not delayed
#
repl-diskless-sync-delay 5


Specifies the interval for the slave to ping the master. The default interval is 10 seconds.
#
# repl-ping-replica-period 10


Set the batch data transfer time or ping reply interval for the master database. The default value is 60 seconds.
# The master node sends the RDB snapshot file to the Replica node. If the REPLICA takes longer than 60 seconds, the Replica node considers the replica failed.
This parameter can be adjusted appropriately (for gigabit network adapter machine, generally 100MB, 6GB file transfer per second, probably more than 60 seconds)
# repl-timeout 60


# Specifies whether to disable the NO_DELAY option of the socket when synchronizing data to the slave. If the value is set to yes, NO_DELAY is disabled. Then packets are merged into the TCP stack and sent uniformly.
This reduces the number of packets between the master and slave nodes and saves bandwidth, but increases the time for data synchronization to the slave. If NO_DELAY is set to no, NO_DELAY is enabled.
# then TCP protocol stack will not delay the packet sending time, so the delay of data synchronization will be reduced, but more bandwidth is required. Then the TCP stack will not delay the packet sending time.
In this way, the delay of data synchronization will be reduced, but more bandwidth is required. Normally, you should set it to NO to reduce synchronization latency,
The value can be set to yes if the network load between the primary and secondary nodes is already high.
repl-disable-tcp-nodelay no


Set the primary/secondary replication backlog size. The backlog is a buffer used to store slave data when slaves are disconnected,
So when a slave wants to reconnect, it usually doesn't want all of it to be resynchronized, but only part of it.
# Pass only the part of data that slave lost when disconnected. The greater the value, the longer the salve can be disconnected.
#
# repl-backlog-size 1mb


# A value of 0 means to never release the backlog.
Configure the number of seconds after the master and slave lose contact. Clear the backlog to free space. If the value is set to 0, the value is never cleared.
#
# repl-backlog-ttl 3600


# Redis Sentinel selects a new master from Slaves when the master is not working properly, the smaller the value,
# is preferred, but 0 means that the slave cannot be selected. The default priority is 100.
replica-priority 100


If the number of healthy slaves in the min-replicas-write function is less than N, mater is disabled.
The master must have at least N healthy slaves alive to execute the write command. Although this configuration does not guarantee that all the N slaves will receive the master's write operation,
# But it can be avoided if there are not enough healthy slaves, the master cannot write to avoid data loss. If the value is set to 0, the function is disabled.
A slave is considered healthy only when its latency is less than min-replicas-max-lag seconds
#
# min-replicas-to-write 3
# min-replicas-max-lag 10


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # SECURITY safety # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# redis connection password
#
requirepass 123456

Rename the command. For security reasons, you can rename some important and dangerous commands. You cancel a command when you rename it to an empty string.
# rename-command CONFIG b4dw78w47d15w4d8w, rename CONFIG command b4dw78w47d15w4d8w; Rename -command CONFIG "" disables CONFIG
#
# rename-command CONFIG ""


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # CLIENTS client # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #


# set the maximum number of concurrent client connections that Redis can open at the same time to the maximum number of file descriptors that Redis processes can open at the same time.
If maxClients is set to 0, no limit is set. Redis closes new connections and returns a Max number of clients reached error message to the client.
#
# maxclients 10000

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # the MEMORY MANAGEMENT, MEMORY MANAGEMENT, # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# set the maximum memory limit for Redis. When Redis starts up, data will be loaded into memory. When the maximum memory is reached, Redis will first attempt to clear expired or expiring keys.
# When the Max memory setting is still reached, no more writing can be done, but reading can still be done.
# Redis new VM mechanism, the Key will be stored in memory, Value will be stored in the swap format: maxmemory 
      
       .
      
#
# maxmemory <bytes>


The clear strategy redis uses when memory usage reaches its maximum. You can choose from the following:
# 1: volatile-lru -> Use the volatile lRU algorithm to remove keys that have expired.
# 2: allkeys-lRU -> Remove any keys using the LRU algorithm
# 3: Volatile - lFU -> Remove keys with expiration time using the LFU algorithm.
# 4: allkeys-lFU -> Remove any keys using the LFU algorithm
# 3) volatile-random -> Remove random keys with expiration dates
# 4) allkeys-random -> remove random keys
# 5) volatile- TTL -> Remove key that is about to expire (minor TTL)
Noeviction noeviction does not remove any key, just returns a write error. The default option
#
# maxmemory-policy noeviction


# LRU and minimal TTL algorithms are not accurate algorithms, but relatively accurate algorithms (in order to save memory), you can choose the sample size for detection.
# Redis selects 5 samples by default for testing, you can set the number of samples with maxmemory-samples.
#
# maxmemory-samples 5


Whether to enable salve maximum memory
# 
# replica-ignore-maxmemory yes

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # LAZY FREEING blocking the way to release the memory? # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Delete key (value); delete key (value); delete key (value); delete key (value);
Configure whether to free memory in a non-blocking manner

lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # APPEND ONLY MODE APPEND MODE # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #


# Please check http://redis.io/topics/persistence for more information.
Whether to enable aOF persistence That is, whether to log after each update operation. The default setting is no.
# Data is written to disks asynchronously. If this function is not enabled, some data may be lost in the event of a power failure.
# AOF and RDB can be enabled at the same time. If AOF is enabled, AOF will be used for recovery
#
appendonly no


Appendone.aof specifies the file name of the append mode. Default: appendone.aof
#
appendfilename "appendonly.aof"


# aof How often files are refreshed. There are three: Everysec is recommended
# 1: No relies on OS to refresh, redis does not actively refresh AOF, this is the fastest, but the security is poor.
# 2: Always calls fsync to flush to AOF file every time a modification command is committed. Very, very slow, but very safe.
# 3: Everysec calls fsync every second to refresh to AOF files, which is fast, but may lose data in less than a second.
#
# appendfsync always
appendfsync everysec
# appendfsync no


# specifies whether fsync should be called during the rewrite aof file in the background. The default is no, indicating that fsync should be called (whether or not a child process is flushing in the background).
# Redis there is a lot of disk IO in the background during RDB file writing or AOF file rewriting, at which point calling fsync may block on some Linux systems.
#
no-appendfsync-on-rewrite no


Redis can call BGREWRITEAOF to rewrite the log file when the AOF file grows to a certain size. When the growth rate of AOF file size is greater than this configuration item, the override is automatically enabled.
auto-aof-rewrite-percentage 100
Redis can call BGREWRITEAOF to rewrite the log file when the AOF file grows to a certain size. When the AOF file size is larger than this configuration item, the override function is automatically enabled.
auto-aof-rewrite-min-size 64mb


# Redis can load truncated AOF files at startup without first executing the Redis-check-aof tool.
aof-load-truncated yes


# When loading redis, you can recognize the AOF file as a string beginning with "redis" and load the RDB file with the prefix, then continue loading the AOF tail
aof-use-rdb-preamble yes

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # LUA SCRIPTING LUA script # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #


# The maximum execution time of a Lua script, in milliseconds. 0 or negative indicates unlimited execution time. Default is 5000.
lua-time-limit 5000

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # REDIS CLUSTER REDIS CLUSTER # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

The cluster mode is disabled by default
#
# cluster-enabled yes


The name of the cluster configuration file. Each node has a cluster configuration file to persist the cluster information. This file does not need to be manual
This configuration file is generated and updated by Redis, each Redis cluster node needs a separate configuration file, please make sure to run with the instance of the system
The names of configuration files in the system do not conflict
# cluster-config-file nodes-6379.conf


# Node interconnection timeout threshold. Number of timeout milliseconds for cluster nodes
#
# cluster-node-timeout 15000

Copy the code

I am Chen PI, an ITer in Internet Coding. Search “Chen PI’s JavaLib” in wechat to read the latest articles in the first time oh!

This is the end of sharing ~~

If you find the article helpful, like, favorites, follow, comment on yours