Ejemplo n.º 1
0
<?php

require_once dirname(__FILE__) . '/lib/redis.php';
require_once dirname(__FILE__) . '/lib/redis.pool.php';
require_once dirname(__FILE__) . '/lib/redis.peer.php';
$redis_pool = array('master' => array('full.host.name', 6379));
# Redis init
redis_pool::add_servers($redis_pool);
class note extends redis_peer
{
}
$note = new note();
# Create note, primary key is generated automatically
$id = $note->insert(array('title' => 'Hello', 'body' => 'world!'));
# Update note
$id = $note->update($id, array('body' => 'wwwwworld!'));
# Get some note by primary key
$note_data = $note->get_by_id($id);
# Delete note
$note->delete($id);
Ejemplo n.º 2
0
<?php

require_once dirname(__FILE__) . '/../lib/redis.php';
require_once dirname(__FILE__) . '/../lib/redis.pool.php';
require_once dirname(__FILE__) . '/../lib/redis_list.peer.php';
require_once dirname(__FILE__) . '/test.lib.php';
# Config
redis_pool::add_servers(array('master' => array('127.0.0.1', 6379)));
class mock_list_peer extends redis_list_peer
{
}
# Tests
$p = new mock_list_peer();
$p->clear('list');
$p->insert('list', array('id' => 1, 'type' => 'image'));
$p->insert('list', array('id' => 2, 'type' => 'text'));
$p->insert('list', array('id' => 3, 'type' => 'video'));
$p->insert('list', array('id' => 4, 'type' => 'video'));
$v = $p->get_list('list');
test::assert_value(count($v), 4, 'Adding, reading');
test::assert_value($p->length('list'), 4);
test::assert_value($v[1]['id'], 2);
test::assert_value($v[3]['type'], 'video');
$v = $p->get_list('list', array(), 1);
test::assert_value(count($v), 1);
test::assert_value($v[0]['id'], 1);
test::assert_value($v[0]['type'], 'image');
$v = $p->get_list('list', array(), 1, 2);
test::assert_value(count($v), 1);
test::assert_value($v[0]['id'], 3);
test::assert_value($v[0]['type'], 'video');
 /**
  * @return php_redis
  */
 public function get_connection()
 {
     return redis_pool::get('master');
 }