Skip to content

Commit

Permalink
Merge pull request #4 from thousandsofthem/master
Browse files Browse the repository at this point in the history
Added Redis example.
  • Loading branch information
CloudMarc committed Dec 4, 2011
2 parents 1e71e44 + 9a344fd commit 4c62ce0
Show file tree
Hide file tree
Showing 7 changed files with 622 additions and 0 deletions.
25 changes: 25 additions & 0 deletions testRedis.php
@@ -0,0 +1,25 @@
<?php
include("SimpleWorker.class.php");

$name = "testRedis.php-".microtime(true);

$sw = new SimpleWorker('config_sw.ini');
$sw->debug_enabled = true;

$project_id = ""; # using default project_id from config
$zipName = "code/$name.zip";

$zipFile = SimpleWorker::zipDirectory(dirname(__FILE__)."/worker_examples/php_redis", $zipName, true);

$res = $sw->postCode($project_id, 'testRedis.php', $zipName, $name);
$task_id = $sw->postTask($project_id, $name);
echo "task_id = $task_id \n";
sleep(10);
$details = $sw->getTaskDetails($project_id, $task_id);
print_r($details);

if ($details->status != 'queued'){
$log = $sw->getLog($project_id, $task_id);
print_r($log);
}

55 changes: 55 additions & 0 deletions worker_examples/php_redis/lib/redis.peer.php
@@ -0,0 +1,55 @@
<?

/**
* Peer class used for entity saving without any list functionality
*/
class redis_peer
{
protected $name_space;

public function __construct()
{
$this->name_space = get_class($this);
}

/**
* @return php_redis
*/
public function get_connection()
{
return redis_pool::get('master');
}

public function next_id()
{
return $this->get_connection()->inc($this->name_space . 'pk');
}

public function last_id()
{
return $this->get_connection()->get($this->name_space . 'pk');
}

public function insert( $data )
{
$data['id'] = $this->next_id();
$this->get_connection()->set($this->name_space . 'item' . $data['id'], $data);
return $data['id'];
}

public function update( $id, $data )
{
$data = array_merge($this->get_by_id($id), $data);
$this->get_connection()->set($this->name_space . 'item' . $id, $data);
}

public function get_by_id( $id )
{
return $this->get_connection()->get($this->name_space . 'item' . $id);
}

public function delete( $id )
{
return $this->get_connection()->delete($this->name_space . 'item' . $id);
}
}

0 comments on commit 4c62ce0

Please sign in to comment.