hyperf-chat/app/Cache/Repository/ListRedis.php

79 lines
1.4 KiB
PHP
Raw Normal View History

2021-05-20 16:53:34 +08:00
<?php
namespace App\Cache\Repository;
use App\Cache\Contracts\ListRedisInterface;
/**
* Redis List
*
* @package App\Cache\Repository
*/
2021-05-21 22:56:42 +08:00
class ListRedis extends AbstractRedis implements ListRedisInterface
2021-05-20 16:53:34 +08:00
{
2021-05-21 22:56:42 +08:00
protected $prefix = 'rds-list';
2021-05-20 16:53:34 +08:00
2021-05-21 22:56:42 +08:00
protected $name = 'default';
2021-05-20 16:53:34 +08:00
/**
* Push 队列任务
*
* @param string ...$value
* @return false|int
*/
public function push(string ...$value)
{
2021-05-21 22:56:42 +08:00
return $this->redis()->lPush($this->getCacheKey(), ...$value);
2021-05-20 16:53:34 +08:00
}
/**
* 获取队列中的任务
*
* @return bool|mixed
*/
public function pop()
{
2021-05-21 22:56:42 +08:00
return $this->redis()->rPop($this->getCacheKey());
2021-05-20 16:53:34 +08:00
}
/**
* 获取列表中元素总数
*
* @return int
*/
public function count()
{
2021-05-21 22:56:42 +08:00
return (int)$this->redis()->lLen($this->getCacheKey());
2021-05-20 16:53:34 +08:00
}
/**
* 清除列表中所有元素
*
* @return boolean
*/
public function clear()
{
2021-05-21 22:56:42 +08:00
return $this->redis()->lTrim($this->getCacheKey(), 1, 0);
2021-05-20 16:53:34 +08:00
}
/**
* 获取列表中所有元素
*
* @return array
*/
public function all()
{
2021-05-21 22:56:42 +08:00
return $this->redis()->lRange($this->getCacheKey(), 0, -1);
2021-05-20 16:53:34 +08:00
}
/**
* 删除 List
*
* @return bool
*/
public function delete()
{
2021-05-21 22:56:42 +08:00
return (bool)$this->redis()->del($this->getCacheKey());
2021-05-20 16:53:34 +08:00
}
}