English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis SCAN Befehl

Redis key (key)

Der Redis Scan Befehl wird verwendet, um die Datenbank-Schlüssel in der Datenbank zu iterieren.

Der SCAN-Befehl ist ein auf einem Cursor basierender Iterator, der nach jedem Aufruf einem Benutzer einen neuen Cursor zurückgibt. Bei der nächsten Iteration muss dieser neue Cursor als Cursorparameter des SCAN-Befehls verwendet werden, um den vorherigen Iterationsprozess fortzusetzen.

SCAN returns an array containing two elements, the first element is the new cursor used for the next iteration, and the second element is an array that contains all the elements that have been iterated over. If the new cursor returns 0, it means the iteration has ended.

Related Commands:

  • SSCAN Command used to iterate over the elements in a set key.
  • HSCAN Command used to iterate over the key-value pairs in a hash key.
  • ZSCAN Command used to iterate over the elements of a sorted set (including element members and element scores).

Syntax

Basic Syntax of redis Scan Command:

SCAN cursor [MATCH pattern] [COUNT count]
  • cursor - Cursor.
  • pattern - Matching pattern.
  • count - Specify how many elements to return from the dataset, the default value is 10 .

Available Version

>= 2.8.0

Return Value

Array List.

Online Example

Iterate using the SCAN command:
redis 127.0.0.1:6379> scan 0   # Using 0 as the cursor to start a new iteration
1) "17"                        # The cursor returned from the first iteration
2)  1) "key:12"
    2) "key:8"
    3) "key:4"
    4) "key:14"
    5) "key:16"
    6) "key:17"
    7) "key:15"
    8) "key:10"
    9) "key:3"
   10) "key:7"
   11) "key:1"
redis 127.0.0.1:6379> scan 17  # The cursor returned from the first iteration is used 17 Start a new iteration
1) "0"
2) 1) "key:5"
   2) "key:18"
   3) "key:0"
   4) "key:2"
   5) "key:19"
   6) "key:13"
   7) "key:6"
   8) "key:9"
   9) "key:11"

Redis key (key)