|
15 | 15 | |[pexpireAt](#pexpireAt) |Set the expiration for a key as a UNIX timestamp with millisecond precision |:white\_check\_mark: |:white\_check\_mark: |Keys |pexpireAt | |
16 | 16 | |[keys](#keys) |Find all keys matching the given pattern |:white\_check\_mark: |:white\_check\_mark: |Keys |keys | |
17 | 17 | |[getKeys](#getKeys) |Find all keys matching the given pattern |:white\_check\_mark: |:white\_check\_mark: |Keys |getKeys | |
18 | | -|[scan](#scan) | Scan for keys in the keyspace (Redis >= 2.8.0) |:x: |:x: |Keys |scan | |
19 | | -|[migrate](#migrate) | Atomically transfer a key from a Redis instance to another one |:x: |:x: |Keys |migrate | |
20 | | -|[move](#move) | Move a key to another database |:x: |:x: |Keys |move | |
21 | | -|[object](#object) | Inspect the internals of Redis objects |:x: |:x: |Keys |object | |
22 | | -|[persist](#persist) | Remove the expiration from a key |:x: |:x: |Keys |persist | |
23 | | -|[randomKey](#randomKey) | Return a random key from the keyspace |:x: |:x: |Keys |randomKey | |
24 | | -|[rename](#rename) | Rename a key |:x: |:x: |Keys |rename | |
25 | | -|[renameKey](#renameKey) | Rename a key |:x: |:x: |Keys |renameKey | |
26 | | -|[renameNx](#renameNx) | Rename a key, only if the new key does not exist |:x: |:x: |Keys |renameNx | |
27 | | -|[type](#type) | Determine the type stored at key |:x: |:x: |Keys |type | |
| 18 | +|[scan](#scan) | Scan for keys in the keyspace (Redis >= 2.8.0) |:white\_check\_mark: |:white\_check\_mark: |Keys |scan | |
| 19 | +|[migrate](#migrate) | Atomically transfer a key from a Redis instance to another one |:white\_check\_mark: |:white\_check\_mark: |Keys |migrate | |
| 20 | +|[move](#move) | Move a key to another database |:white\_check\_mark: |:white\_check\_mark: |Keys |move | |
| 21 | +|[object](#object) | Inspect the internals of Redis objects |:white\_check\_mark: |:x: |Keys |object | |
| 22 | +|[persist](#persist) | Remove the expiration from a key |:white\_check\_mark: |:x: |Keys |persist | |
| 23 | +|[randomKey](#randomKey) | Return a random key from the keyspace |:white\_check\_mark: |:x: |Keys |randomKey | |
| 24 | +|[rename](#rename) | Rename a key |:white\_check\_mark: |:x: |Keys |rename | |
| 25 | +|[renameKey](#renameKey) | Rename a key |:white\_check\_mark: |:x: |Keys |renameKey | |
| 26 | +|[renameNx](#renameNx) | Rename a key, only if the new key does not exist |:white\_check\_mark: |:x: |Keys |renameNx | |
| 27 | +|[type](#type) | Determine the type stored at key |:white\_check\_mark: |:x: |Keys |type | |
28 | 28 | |[sort](#sort) | Sort the elements in a list, set or sorted set |:x: |:x: |Keys |sort | |
29 | | -|[ttl](#ttl) | Get the time to live for a key |:x: |:x: |Keys |ttl | |
30 | | -|[pttl](#pttl) | Get the time to live for a key |:x: |:x: |Keys |pttl | |
31 | | -|[restore](#restore) | Create a key using the provided serialized value, previously obtained with dump. |:x: |:x: |Keys |restore | |
| 29 | +|[ttl](#ttl) | Get the time to live for a key |:white\_check\_mark: |:x: |Keys |ttl | |
| 30 | +|[pttl](#pttl) | Get the time to live for a key |:white\_check\_mark: |:x: |Keys |pttl | |
| 31 | +|[restore](#restore) | Create a key using the provided serialized value, previously obtained with dump. |:white\_check\_mark: |:x: |Keys |restore | |
32 | 32 |
|
33 | 33 | ## del |
34 | 34 |
|
@@ -412,3 +412,135 @@ array(3) { |
412 | 412 | } |
413 | 413 | */ |
414 | 414 | ``` |
| 415 | + |
| 416 | +## scan |
| 417 | + |
| 418 | +_**Description**_: Scan the keyspace for keys. |
| 419 | + |
| 420 | +##### *Prototype* |
| 421 | + |
| 422 | +```php |
| 423 | +public function scan($iterator = null, string $pattern = '*', int $count = 10) { |
| 424 | + return $this->redis->scan($iterator, $pattern, $count); |
| 425 | +} |
| 426 | +``` |
| 427 | + |
| 428 | +##### *Parameters* |
| 429 | + |
| 430 | +- *iterator*: String. LONG (reference): Iterator, initialized to NULL. |
| 431 | +- *pattern*: String. Pattern to match, using '\*' as a wildcard. |
| 432 | +- *count*: Integer. LONG, Optional: Count of keys per iteration (only a suggestion to Redis). |
| 433 | + |
| 434 | +##### *Return value* |
| 435 | + |
| 436 | +*array*: Array, boolean: This function will return an array of keys or FALSE if Redis returned zero keys. |
| 437 | + |
| 438 | +##### *Example* |
| 439 | + |
| 440 | +```php |
| 441 | +/* Without enabling Redis::SCAN_RETRY (default condition) */ |
| 442 | +$it = NULL; |
| 443 | +do { |
| 444 | + // Scan for some keys |
| 445 | + $arr_keys = $redis->scan($it); |
| 446 | + |
| 447 | + // Redis may return empty results, so protect against that |
| 448 | + if ($arr_keys !== FALSE) { |
| 449 | + foreach($arr_keys as $str_key) { |
| 450 | + echo "Here is a key: $str_key\n"; |
| 451 | + } |
| 452 | + } |
| 453 | +} while ($it > 0); |
| 454 | +echo "No more keys to scan!\n"; |
| 455 | + |
| 456 | +/* With Redis::SCAN_RETRY enabled */ |
| 457 | +$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); |
| 458 | +$it = NULL; |
| 459 | + |
| 460 | +/* phpredis will retry the SCAN command if empty results are returned from the |
| 461 | + server, so no empty results check is required. */ |
| 462 | +while ($arr_keys = $redis->scan($it)) { |
| 463 | + foreach ($arr_keys as $str_key) { |
| 464 | + echo "Here is a key: $str_key\n"; |
| 465 | + } |
| 466 | +} |
| 467 | +echo "No more keys to scan!\n"; |
| 468 | +``` |
| 469 | + |
| 470 | +## migrate |
| 471 | + |
| 472 | +_**Description**_: Migrates a key to a different Redis instance. |
| 473 | + |
| 474 | +Note:: Redis introduced migrating multiple keys in 3.0.6, so you must have at least that version in order to call migrate with an array of keys. |
| 475 | + |
| 476 | +##### *Prototype* |
| 477 | + |
| 478 | +```php |
| 479 | +public function migrate( |
| 480 | + string $host, |
| 481 | + int $port, |
| 482 | + array $keys, |
| 483 | + int $db, |
| 484 | + int $timeout, |
| 485 | + ?bool $copy = false, |
| 486 | + ?bool $replace = false |
| 487 | +) : bool { |
| 488 | + return $this->redis->migrate($host, $port, $keys, $db, $timeout); |
| 489 | +} |
| 490 | +``` |
| 491 | + |
| 492 | +##### *Parameters* |
| 493 | + |
| 494 | +- *host*: String. The destination host. |
| 495 | +- *port*: Integer. The TCP port to connect to. |
| 496 | +- *keys*: Array. Key(s) to be moved. |
| 497 | +- *db*: Integer. The target DB. |
| 498 | +- *timeout*: Integer. The maximum amount of time given to this transfer. |
| 499 | +- *copy*: Boolean. (optional) Should we send the COPY flag to redis. |
| 500 | +- *replace*: Boolean. (optional) Should we send the REPLACE flag to redis. |
| 501 | + |
| 502 | +##### *Return value* |
| 503 | + |
| 504 | +*array*: Array of string: The keys that match a certain pattern. |
| 505 | + |
| 506 | +##### *Example* |
| 507 | + |
| 508 | +```php |
| 509 | +$redis->migrate('backup', 6379, 'foo', 0, 3600); |
| 510 | +$redis->migrate('backup', 6379, 'foo', 0, 3600, true, true); /* copy and replace */ |
| 511 | +$redis->migrate('backup', 6379, 'foo', 0, 3600, false, true); /* just REPLACE flag */ |
| 512 | + |
| 513 | +/* Migrate multiple keys (requires Redis >= 3.0.6) |
| 514 | +$redis->migrate('backup', 6379, ['key1', 'key2', 'key3'], 0, 3600); |
| 515 | +``` |
| 516 | + |
| 517 | +## move |
| 518 | + |
| 519 | +_**Description**_: Moves a key to a different database. |
| 520 | + |
| 521 | +##### *Prototype* |
| 522 | + |
| 523 | +```php |
| 524 | +public function move(string $key, int $db): bool { |
| 525 | + return $this->redis->move($key, $db); |
| 526 | +} |
| 527 | +``` |
| 528 | + |
| 529 | +##### *Parameters* |
| 530 | + |
| 531 | +- *key*: String. the key to move. |
| 532 | +- *db*: Integer. dbindex, the database number to move the key to. |
| 533 | + |
| 534 | +##### *Return value* |
| 535 | + |
| 536 | +*bool*: true in case of success, false in case of failure. |
| 537 | + |
| 538 | +##### *Example* |
| 539 | + |
| 540 | +```php |
| 541 | +$redis->select(0); // switch to DB 0 |
| 542 | +$redis->set('x', '42'); // write 42 to x |
| 543 | +$redis->move('x', 1); // move to DB 1 |
| 544 | +$redis->select(1); // switch to DB 1 |
| 545 | +$redis->get('x'); // will return 42 |
| 546 | +``` |
0 commit comments