Meaning of redis scan count / binary security issues

redis is single-threaded, keys similar query key hbase full table scan (can also be understood as select *), when a large amount of data is very time-consuming, so the official gives the scan, scan using similar databases page, you can specify how many queries Description element, the official website of the scan is a traverse, but you can specify how many elements each query with count

Syntax: scan cursor match pattern count num

cursor: the cursor, the default starting from 0, each execution scan position of the cursor will return in addition to returning query results, even if a particular query result is empty, and do not represent the end of the traverse, return only when the cursor is 0, can represent traversal End

match: The default is *, matching the specified element

count: The default is 10, the bottom of redis achieve similar java hashmap, are the hash table, so the real data is stored in an array, count specifies the number of array elements per query

In summary: Query count the number of scan element returns to meet the match criteria

To operate using Jedis redis

. 1  @Test
 2      public  void test2 () {
 . 3          Jedis jedis = new new Jedis ( "192.168.101.101" );
 . 4          System.out.println (jedis.ping ());
 . 5  
. 6  
. 7          // results returned by a single 0 0 does not mean the end of the traversal, only when the cursor is returned to 0 when the representative of the end of traversal 
. 8          String cursor = ScanParams.SCAN_POINTER_START;
 . 9  
10          ScanParams the params = new new ScanParams ();
 . 11          // default number count is 10, is not limited count returns the number of results,
 12          // number of array but a single pass through the element (Redis underlying hash table is implemented, so that the storage of data array), which returns the matched elements
 13          //When more element, and the count set relatively small, this case may perform multiple queries 
14          params.count (10 );
 15          params.match ( "U *" );
 16  
. 17          ScanResult <String> scanResult;
 18 is          Boolean In Flag = to true ;
 . 19          the while (In Flag) {
 20 is              scanResult = jedis.scan (Cursor, the params);
 21 is              Cursor = scanResult.getCursor ();
 22 is              IF (the Integer.parseInt (Cursor) == 0 ) {
 23 is                  In Flag = to false ;
 24              }
 25             System.out.println(cursor);
26             scanResult.getResult().forEach(i -> System.out.println(i));
27         }
28 
29         jedis.close();
30     }

There are similar hscan (hash), zscan (zset), sscan (set), not repeat them

 

What is binary safe? For example, you open a picture with the word, display is garbled, if you modify these garbled, and then open the picture viewer pictures you will find pictures not open, this operation is a non-binary safe

Another example, when writing a file and write files encoded with coding inconsistencies, will generate a lot of meaningless gibberish after writing, it is easy to cause the file does not display properly, c language will default space as end of the string, This leads to the loss of the contents of c problems when saving string, the string is redis underlying storage sds, although using an array of char, but inwardly they are saved byte, in addition redis no strings set any modification of the filter and, from this point of view redis binary safe, maximum string lengths may store the video, audio, redis are similar in java hashmap, list, etc. are pre-allocated extra space 512M, mode expansion , thereby reducing the frequent memory allocation brings performance overhead

Guess you like

Origin www.cnblogs.com/tele-share/p/11449502.html