keys, scan, bigkeys, key storage methods

keys, scan, bigkeys, key storage methods

keys

keys regular expressions to find all meet the requirements of the key, but this directive has several drawbacks, the first is no limit parameters, can detect over more data, and that it is a traversal algorithm complexity is ON, is because redis single-threaded, multi-data if it will lead to redis Caton.

So instead of keys command is a new command: scan

scan

It has some features:

1, the complexity is ON. But he is a cursor step-wise, do not block the thread.

2, there is provided the limit parameter, the fuzzy control can be returned to the maximum number of

3, the only state of the cursor is the return value of the command

4, traversed by the duplicate results may

5, data during traversal changes can not be traversed

use:

scan 0 match the regular expression count 1000

In this case returns a number: set a status of the cursor and

The parameter is then taken into a second state of the cursor position is executed again until the state returns to 0, the iteration is complete does not mean that returns empty set.

The first parameter represents the position of the index scan instruction one-dimensional array, the last parameter represents the number of slots of the visit

(Internal redis All data is a huge dictionary, plus an array of linked lists)

scan is not traversed from the first position to a final position, but with the upper carry adder traversal order is selected, because such a sequence may be omitted to avoid duplication and at the dictionary expansion volume reduction.

Dictionary to expansion in the expansion will double the current size, if eight expansion to 16, to the original slots will be divided in half to about 3 slot 11, this order is the order of traversal, can also ensure that even the expansion not be repeated traversal, if the volume reduction of the number of words will be repeated traversal, since a plurality of positions of the original data is now merged together.

This expansion volume reduction will rehash, java non-progressive, Redis with the rehash is progressive, while retaining the old and new array, gradually shifted in a subsequent timing tasks, find the old and new commands simultaneously Scan array.

Find big key

If a single key is too large, the cluster to migrate data caused great difficulties, when the expansion volume reduction also. Redis Caton big key is the most common cause, there is an instruction can be found in big key:

redis-cll –h 127.0.0.1 –p 701 –bigkeys

You can also add parameters to sleep, to avoid consuming too much resources.

View the key storage

Object key corresponding to the key can be observed by a debug attribute, wherein different encoding its storage, the storage coding, different number of bits stored in different types of data structure employed.

Guess you like

Origin www.cnblogs.com/shizhuoping/p/11522419.html