Redis related functions and practical command (five)

Slow Query Analysis

Since Redis is single-threaded, it maintains an internal command queue, so when there is a time-consuming command appears, for example keys *, the back of the command will be blocked, look up through a slow query can be further optimized for service.

  1. Set slow query threshold: default 10 milliseconds, microseconds

    6379>config set slowlog-log-slower-than 10000

    May be coupled directly modify redis.conf slowlog-log-slower-than 10000

    slow-max-len the number of queries to set the slow

  2. Get slow query execution slowlog get the following format

    img

Usually on a regular basis will be exported to the slow query mysql or other storage for business people to see where there has been slow query

Pipeline pipeline

The article shows how to use the pipeline in the console to import mysql data, but the pipe is generally used in an application

 Object execute = redisTemplate.execute(new RedisCallback<Object>() {
     @Override
     public Object doInRedis(RedisConnection connection) throws DataAccessException {
         connection.openPipeline();
         for (int i = 0; i < 1000000; i++) {
             String key = "123" + i;
             connection.set(key.getBytes(), key.getBytes());
         }
         List<Object> result = connection.closePipeline();
         return result;
     }
 });

Publish-Subscribe (publish / subscribe)

Redis publish-subscribe relatively simple, is not suitable for professional scene, a message will be lost, unable to back issues, subscribe to this publication is generally used for internal use Redis, such as sentinel surveillance

Publish or subscribe to recommend professional use kafka or rabbitmq

rabbitmq can refer to my other article Rabbitmq

Some practical command

  • Query occupancy connections, which hosts much occupied connection for troubleshooting connection problems run out

    redis-cli -a <密码> client list  | awk '{print $1}' | cut -d "=" -f2 | cut -d: -f 1 | sort  -n | uniq -c 
  • Query the current memory usage

    6379> info Memory

  • Returns all key inside a random key, it can be used to draw

    randomkey

    Little promotion

    Writing is not easy, I hope the support of open source software, and my gadgets, welcome to gitee point star, fork, put bug.

Excel common import and export, support Excel formulas
blog address: https://blog.csdn.net/sanri1993/article/details/100601578
gitee: https://gitee.com/sanri/sanri-excel-poi

Use the template code, the gadget generate code from the database, and some projects can often be used in the
blog address: https://blog.csdn.net/sanri1993/article/details/98664034
gitee: https://gitee.com/ sanri / sanri-tools-maven

Guess you like

Origin www.cnblogs.com/sanri1993/p/11610426.html