예제 #1
0
 function testWrite()
 {
     $scope = __FUNCTION__;
     Redis::config(array('format' => $scope));
     $expected = 'bar';
     $this->assertEqual($expected, Redis::write('foo', 'bar'));
     $this->assertEqual($expected, $this->redis->get("{$scope}:foo"));
     $expected = 'baz';
     $this->assertEqual($expected, Redis::write('foo', 'baz'));
     $this->assertEqual($expected, $this->redis->get("{$scope}:foo"));
     $expected = array('bar' => 'baz');
     $this->assertEqual($expected, Redis::write('isHash', array('bar' => 'baz')));
     $this->assertEqual($expected, $this->redis->hGetAll("{$scope}:isHash"));
     $expected = array('field1' => 'val1', 'field2' => 'val2');
     $this->assertEqual($expected, Redis::write('isHash2', array('field1' => 'val1', 'field2' => 'val2')));
     $this->assertEqual($expected, $this->redis->hGetAll("{$scope}:isHash2"));
     $expected = array('bar' => 'baz');
     $this->assertEqual($expected, Redis::write(array('bar' => 'baz')));
     $this->assertEqual('baz', $this->redis->get("{$scope}:bar"));
     $expected = array('key1' => 'val1', 'key2' => 'val2');
     $this->assertEqual($expected, Redis::write(array('key1' => 'val1', 'key2' => 'val2')));
     $this->assertEqual('val1', $this->redis->get("{$scope}:key1"));
     $this->assertEqual('val2', $this->redis->get("{$scope}:key2"));
     $expected = array('key1' => true, 'key2' => false);
     $this->assertEqual($expected, Redis::write(array('key1' => true, 'key2' => false)));
     $this->assertEqual(1, $this->redis->get("{$scope}:key1"));
     $this->assertEqual(null, $this->redis->get("{$scope}:key2"));
 }