Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: tidal/PEIP_Redis
base: a6ec213cd7
...
head fork: tidal/PEIP_Redis
compare: d9de53c1b6
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2011 Timo Michna
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
46 src/Queue/Queue.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace PEIP_Redis\Queue;
+
+/*
+ * This file is part of the PEIP_Redis package.
+ * (c) 2009-2011 Timo Michna <timomichna/yahoo.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Queue
+ * Basic implementation of a Queue using a redis list
+ *
+ * @author Timo Michna <timomichna/yahoo.de>
+ * @package PEIP_Redis
+ */
+
+class Queue {
+
+ protected
+ $client,
+ $key,
+ $timeout;
+
+ public function __construct(\Predis\Client $client, $key, $timeout = 1){
+ $this->client = $client;
+ $this->key = $key;
+ $this->timeout = $timeout;
+ }
+
+ public function enqueue($value){
+ $this->client->rpush($this->key, $value);
+ }
+
+ public function dequeue(){
+ $res = $this->client->blpop($this->key, $this->timeout);
+ return $res[1];
+ }
+
+
+
+
+}
View
44 tests/Queue/QueueTest.php
@@ -0,0 +1,44 @@
+<?php
+require_once __DIR__.'/../../src/Queue/Queue.php';
+require_once __DIR__.'/../bootstrap.php';
+
+class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
+ public $redis;
+
+ protected function setUp() {
+ $this->redis = RC::getConnection();
+ $this->redis->flushdb();
+ }
+
+ public function testEnqueue(){
+ $key = 'bar';
+ $value = 'foo';
+ $queue = new PEIP_Redis\Queue\Queue($this->redis, $key);
+
+ $queue->enqueue($value);
+
+ $this->assertEquals($value, $queue->dequeue());
+ }
+
+ public function testEnqueueError(){
+ $key = 'bar';
+ $value = 'foo';
+ $queue = new PEIP_Redis\Queue\Queue($this->redis, $key);
+
+ $this->assertNotEquals($value, $queue->dequeue());
+ }
+
+ public function testEnqueueTimeout(){
+ $key = 'bar';
+ $value = 'foo';
+ $timeout = 1;
+ $time1 = microtime(1);
+ $queue = new PEIP_Redis\Queue\Queue($this->redis, $key);
+ $queue->dequeue();
+ $this->assertGreaterThanOrEqual($time1 + $timeout, microtime(1));
+ }
+
+
+
+}
+
View
6 tests/bootstrap.php
@@ -0,0 +1,6 @@
+<?php
+
+require_once(__DIR__.'/../src/vendor/predis/test/bootstrap.php');
+
+
+

No commit comments for this range

Something went wrong with that request. Please try again.