/** * add value(s) to a list in redis * * examples to add items include this: * * {{{ * Lists::add('foo', 'bar'); // adds `bar` to a list called `foo` * Lists::add('foo', array('bar', 'baz')); // adds `bar` and `baz` to a list called `foo` * }}} * * @see li3_redis\storage\Redis::listAdd() * @see li3_redis\storage\Redis::getKey() * @param string $key redis key in which to store the hash * @param string|array $values an item or an array of items to add to the list * @param string|array $buckets an array of additional prefixes, can be a numerical indexed * array with strings, or an associated array, in which the key and value will be glued * together by a separater or just a string, for one additional prefix. * @param array $options array with additional options, see Redis::getKey() * @return mixed the number of items in the list, or an array on multiple buckets * @filter */ public static function add($key, $values, $buckets = null, array $options = array()) { $defaults = array('namespace' => static::$namespace); $options += $defaults; $params = compact('key', 'values', 'buckets', 'options'); return static::_filter(__METHOD__, $params, function ($self, $params) { extract($params); if (is_null($buckets)) { return Redis::listAdd($key, $values, $options); } $result = array(); $buckets = !is_array($buckets) ? array($buckets) : $buckets; foreach ($buckets as $prefix => $val) { $options['prefix'] = !is_numeric($prefix) ? Redis::addPrefix($val, $prefix) : $val; $result[$options['prefix']] = Redis::listAdd($key, $values, $options); } return count($result) > 1 ? $result : array_shift($result); }); }