Ver código fonte

Implement PHP iterator based on the SSCAN command (Redis 2.8).

This iterator allows to perform full iterations over the members of a set
by wrapping the incremental nature of SSCAN just like we did for SCAN:

  $client = new Predis\Client('tcp://127.0.0.1', ['profile' => '2.8']);
  $iterator = new Predis\Iterator\Scan\SetIterator($client, "set_key");

  foreach ($iterator as $member) {
      echo $member . PHP_EOL;
  }

Being SSCAN closely related to SCAN, it is subject to the same behaviour,
see http://redis.io/commands/scan for reference.

Meh
Daniele Alessandri 11 anos atrás
pai
commit
7028082b7f
1 arquivos alterados com 47 adições e 0 exclusões
  1. 47 0
      lib/Predis/Iterator/Scan/SetIterator.php

+ 47 - 0
lib/Predis/Iterator/Scan/SetIterator.php

@@ -0,0 +1,47 @@
+<?php
+
+/*
+ * This file is part of the Predis package.
+ *
+ * (c) Daniele Alessandri <suppakilla@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Predis\Iterator\Scan;
+
+use Predis\ClientInterface;
+
+/**
+ * Abstracts the iteration of members stored in a set by
+ * leveraging the SSCAN command (Redis >= 2.8) wrapped in
+ * a fully-rewindable PHP iterator.
+ *
+ * @author Daniele Alessandri <suppakilla@gmail.com>
+ * @link http://redis.io/commands/scan
+ */
+class SetIterator extends AbstractScanIterator
+{
+    protected $key;
+
+    /**
+     * {@inheritdoc}
+     */
+    public function __construct(ClientInterface $client, $key, $match = null, $count = null)
+    {
+        $this->requiredCommand($client, 'SSCAN');
+
+        parent::__construct($client, $match, $count);
+
+        $this->key = $key;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function executeScanCommand()
+    {
+        return $this->client->sscan($this->key, $this->cursor, $this->getScanOptions());
+    }
+}