Redis FAQs and how to handle them

Source: Internet
Author: User
Tags redis server

One, Redis status check

The only token for a Redis instance is IP and port, the frontend is TCP access to Redis, and we provide the app access to a ip+63379 (typically 63379) port. So we perform the following command to check the Redis status:

This value of the above role must be master, as long as the VIP in the master of our Padis cache service is no problem, if the role is not slave, then you have to continue to see what the problem.

Two, two redis roles are slave issues

When two hosts were hung up or we accidentally stopped two Redis, and we checked with the following command

/wls/wls81/redis/bin/redis-cli-h {IP}-p {port}-a {password} info replication

Discover whether the VIP or the other two IP is the role of role:slave, this time need to the VIP host to perform slaveof no one operation, the VIP is located in the Redis into master, such as:

/wls/wls81/redis/bin/redis-cli-h {VIP}-p {port}-a {password} slaveof no one

Iii. Configuration parameters of Sentinel

There are two important configurations in our Sentinel configuration file.

Sentinel Monitor PDS_JKS-CORE-PRD 10.33.94.65 63379 1-----------configured IP and port need to be the master IP port at any time, the program will change automatically when switching. In addition, the red part of PDS_JKS-CORE-PRD is the host name that Redis provides externally, and this name is typically used by Jedis when calling Redis. If multiple sentinels are configured, this name is typically required to uniquely identify

Sentinel down-after-milliseconds pds_jks-core-prd 15000----------This is the timeout period for Sentinel connection master, More than this time to think of Master hung, the implementation of automatic switching. This default is 30 seconds, this time to adjust, big will be in real failure when the time to switch the president, small sometimes master due to persistent data, busy does not respond, will lead to automatic switching, the actual is only instantaneous is not available, now think set to 15 seconds appropriate.

Iv. aof Log

This log records every write command or delete command, this is useful for our audit function, because of the use of a lot of disk, the default we are closed

If enabled, a. aof file is generated in the data file. such as:/wls/apache/servers/pds_jks-core-prd/data

Open in Redis run:

/wls/wls81/redis-icore/bin/redis-cli-h {IP}-p {port}-a {password} config set appendonly Yes

Turn on the ability to view logs, record each command, and turn it off if necessary to open the check. Also explain

/wls/wls81/redis-icore/bin/redis-cli-h {IP}-p {port}-a {password} config set can set more than one of its parameters while Redis is running

V. Timeout for idle connections

The Redis server does not automatically disconnect the client from the connection, and the Redis server has set the client idle connection time-out, available commands

/wls/wls81/redis-icore/bin/redis-cli-h {IP}-p {port}-a {password} config get timeout

Check the current timeout time, default is 0, is to keep the idle connection, if you do not disconnect the idle connection, it will cause too many redis connections

So you can normally set it to 3,600 seconds:

/wls/wls81/redis-icore/bin/redis-cli-h {IP}-p {port}-a {password} config set timeout 3600

That is, 3,600 seconds after the idle connection is closed off. You can use the following command to see how long a connection has been idle:

/wls/wls81/redis-icore/bin/redis-cli-h {IP}-p {port}-a {password} client list

Vi. monitoring of Redis execution commands

/wls/wls81/redis-icore/bin/redis-cli-h {IP}-p {port}-a {password} monitor

The monitor command above can see what the Redis command is, and sometimes it is necessary to check the problem, and we can know what Redis did during that time to diagnose our problem.

Vii. search and execution of key

/wls/wls81/redis-icore/bin/redis-cli-h {IP}-p {port}-a {password} keys "*"

Keys This command finds all keys, but it is best to use caution because it consumes Redis's performance, and each key is traversed over. You can also make fuzzy matches such as: Keys "send*"

Keep in mind that you can't use it in a production environment because it will run out of redis performance and cause other connections to get unresponsive.

/wls/wls81/redis/bin/redis-cli-h {IP}-p {port}-a {password} dbsize

Dbsize This command can see how many keys are in the whole redis, and of course the keys "*" | Wc-l The result is the same.

When we need to delete the key value in bulk, we can use the following command:

/wls/wls81/redis/bin/redis-cli-h {IP}-p {port}-a {password} keys "send*" | xargs/wls/wls81/redis/bin/redis-cli-h {IP}-p {port}-a {password} del

We need to flush out the entire db to use:

/wls/wls81/redis/bin/redis-cli-h {IP}-p {port}-a {password}-a MAMCCOREPRD flushdb

/wls/wls81/redis/bin/redis-cli-h {IP}-p {port}-a {password}-a Flushall

Viii. because the client connecting to Redis uses Jedispool

If you set the

Redis.pool.testonborrow.rel=true

Redis.pool.testonreturn.rel=true

These two parameters are said that the connection in the pool or the return connection to the pool will need to check the usefulness of the connection, that is, ping this redis is not good,

This way, when high concurrency occurs, the ping operation is slow relative to thread startup due to too many concurrent threads, so the application is stuck in a location similar to the following thread dump

"[ACTIVE] Executethread: ' For queue: ' Weblogic.kernel.Default (self-tuning) '" Id=33 idx=0x9c tid=273669 prio=5 Alive, native_blocked, daemon

At jrockit/net/socketnativeio.readbytespinned (ljava/io/filedescriptor;[ BIII) I (Native Method)

At Jrockit/net/socketnativeio.socketread (socketnativeio.java:32)

At Java/net/socketinputstream.socketread0 (ljava/io/filedescriptor;[ BIII) I (Socketinputstream.java)

At Java/net/socketinputstream.read (socketinputstream.java:129)

At Java/net/socketinputstream.read (socketinputstream.java:90)

At Redis/clients/util/redisinputstream.fill (redisinputstream.java:109)

At Redis/clients/util/redisinputstream.readbyte (redisinputstream.java:45)

At Redis/clients/jedis/protocol.process (protocol.java:64)

At Redis/clients/jedis/protocol.read (protocol.java:131)

At Redis/clients/jedis/jedis.ping (jedis.java:35)

At Redis/clients/jedis/jedispool$jedisfactory.validateobject (jedispool.java:104)

At Org/apache/commons/pool/impl/genericobjectpool.addobjecttopool (genericobjectpool.java:922)

At Org/apache/commons/pool/impl/genericobjectpool.returnobject (genericobjectpool.java:917)

^--Holding lock:org/apache/commons/pool/impl/[email Protected][fat Lock]

At Redis/clients/util/pool.returnresourceobject (pool.java:29)

At Redis/clients/util/pool.returnresource (pool.java:41)

At Com/paic/icore/mams/common/jedis/util/redispoolcachetools.release (redispoolcachetools.java:43)

Although it recovers automatically later, it causes the application to respond slowly. The workaround is to set the two parameters to false and check periodically:

Testonborrow.rel=false

Testonreturn.rel=false

timebetweenevictionrunsmillis=60000-------Check idle connections periodically every 60 seconds

minevictableidletimemillis=120000---------The minimum time value, in milliseconds, that the connection remains idle in the pool and is not reclaimed by the idle connection collector thread

Numtestsperevictionrun=-1----------Idle connection scan, the maximum number of connections scanned per scan, typically set to-1, scan all

Set it up so that you don't have to test it every time, which improves the performance of your application.

Sometimes, because persistence causes master to become slow, it is recommended to turn off master persistence and make slave persistent

Close persistence/wls/wls81/redis/bin/redis-cli-h {IP}-p {port}-a {password} config set save ""

Open persistent/wls/wls81/redis/bin/redis-cli-h {IP}-p {port}-a {password} config set save "900 1 300 10 60 10000"

If the primary standby switch occurs after the persistence is turned off, the persistence of the master is turned off, and the persistence of the slave is turned on

Nine, query the number of commands executed per second

X. Number of commands performed by Redis in unit time

Redis FAQs and how to handle them

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.