<commit_before><?php
namespace Utility;
class WorkBuffer {
	private $_redis;
	private $_prefix = 'wub';
	
	private function _prefix_key(){
		$args = func_get_args();
		array_unshift($args, $this->_prefix);
		return implode('-', $args);
	}
	
	public function __construct(Redis $redis){
		$this->setRedis($redis);
	}
	
	public function setRedis(Redis $redis){
		$this->_redis = $redis;
	}
	
	public function buffer(WorkItem $work){
		$queue = $this->_prefixKey($work->getBufferName(), 'queue');
		$this->_setWorkItem($key, $work);
		
		//store data before queueing
		return $this->_redis->lPush($queue, $id); //'beginning' of the list is actually the last to process
	}
	
	public function hasNext($key){
		$key = $this->_prefixKey($key, 'queue');
		return ($this->_redis->lLen($key) > 0);
	}
	
	public function getNext($key, $timeout = 1000){
		$queue = $this->_prefixKey($key, 'queue' );
		$process = $this->_prefixKey($key, 'process');
		
		$id = $this->redis->bRPopLPush($queue, $process, $timeout);
		
		if($id){<commit_msg>Update WorkBuffer.php<commit_after><?php
namespace Utility;
class WorkBuffer {
	private $_redis;
	private $_prefix = 'wub';
	
	private function _prefix_key(){
		$args = func_get_args();
		array_unshift($args, $this->_prefix);
		return implode('-', $args);
	}
	
	public function __construct(Redis $redis){
		$this->setRedis($redis);
	}
	
	public function setRedis(Redis $redis){
		$this->_redis = $redis;
	}
	
	public function buffer(WorkItem $work){
		$queue = $this->_prefixKey($work->getBufferName(), 'queue');
		$this->_setWorkItem($key, $work);//store data before queueing
		
		return $this->_redis->lPush($queue, $id); //'beginning' of the list is actually the last to process
	}
	
	public function hasNext($key){
		$key = $this->_prefixKey($key, 'queue');
		return ($this->_redis->lLen($key) > 0);
	}
	
	public function getNext($key, $timeout = 1000){
		$queue = $this->_prefixKey($key, 'queue' );
		$process = $this->_prefixKey($key, 'process');
		
		$id = $this->redis->bRPopLPush($queue, $process, $timeout);
		
		if($id){
{'fraction_non_alphanumeric': 0.18327661643169665, 'fraction_numerical': 0.004861448711716091, 'mean_word_length': 4.653846153846154, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1439188', 'n_tokens_mistral': 786, 'n_tokens_neox': 704, 'n_words': 163}