-
Notifications
You must be signed in to change notification settings - Fork 56
/
ARedisIterableEntity.php
executable file
·85 lines (74 loc) · 1.95 KB
/
ARedisIterableEntity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* A base class for iterable redis entities (lists, hashes, sets and sorted sets)
* @author Charles Pick
* @package packages.redis
*/
abstract class ARedisIterableEntity extends ARedisEntity implements IteratorAggregate,ArrayAccess,Countable {
/**
* The number of items in the entity
* @var integer
*/
protected $_count;
/**
* Holds the data in the entity
* @var array
*/
protected $_data;
/**
* Returns an iterator for traversing the items in the set.
* This method is required by the interface IteratorAggregate.
* @return Iterator an iterator for traversing the items in the set.
*/
public function getIterator()
{
$data = $this->getData();
return new CListIterator($data);
}
/**
* Returns the number of items in the set.
* This method is required by Countable interface.
* @return integer number of items in the set.
*/
public function count()
{
return $this->getCount();
}
/**
* Gets a list of items in the set
* @return array the list of items in array
*/
public function toArray()
{
return $this->getData();
}
/**
* Gets the number of items in the entity
* @return integer the number of items in the entity
*/
abstract public function getCount();
/**
* Gets all the members in the entity
* @param boolean $forceRefresh whether to force a refresh or not
* @return array the members in the entity
*/
abstract public function getData($forceRefresh = false);
/**
* Determines whether the item is contained in the entity
* @param mixed $item the item to check for
* @return boolean true if the item exists in the entity, otherwise false
*/
public function contains($item) {
return in_array($item, $this->getData());
}
/**
* Removes all the items from the entity
* @return ARedisIterableEntity the current entity
*/
public function clear() {
$this->_data = null;
$this->_count = null;
$this->getConnection()->getClient()->delete($this->name);
return $this;
}
}