怎么自己制作网站链接,wordpress设置主页标题,网站建设实训意义,本科自考是什么意思啊项目开发过程中需要设计提供可平衡的处理多个用户请求的队列。需求#xff1a;当用户登录后#xff0c;查看系统中已经登录的管理员队列#xff0c;然后查看后台管理员的处理能力#xff0c;如果已经不能处理新的请求#xff0c;则把该管理员从处理队列中删除#xff0c;…项目开发过程中需要设计提供可平衡的处理多个用户请求的队列。 需求 当用户登录后查看系统中已经登录的管理员队列然后查看后台管理员的处理能力如果已经不能处理新的请求则把该管理员从处理队列中删除否则把 该管理员分配给该用户管理员的处理能力减一,系统当前所指向的管理员1即指向下一位可以处理问题的管理员。 分析 最简单的设计就是维护一个循环链表的队列可以方便的删除和修改信息但是Redis中并不能处理这样复制的结构信息因此只能另辟蹊径了考虑使用 二重的结构来转换循环链表结构。先看下原来的结构 这样的结构可以方便的处理问题不过在redis中存储这样的结构并不能轻易的做到于是考虑使用用户ID建立队列list然后使用用户ID建立key,value)当然也可以把 用户的信息建立一个以ID为KEY的list,于是经过这样的二级结构的转换Redis就可以处理原本复杂的结构了这里处理的时候先检查主队列元素然后根据以值为 Key来获取其他复杂的信息进行处理这样设计的结构 这样的结构无论删除或者添加都必须操作两个地方....以操作的复杂性换取存储的复杂性未必设计的好不过先用来实现功能再说吧。 Redis类 ?php if (!defined(BASEPATH))exit(No direct script access allowed); class Redisdb { private $size ; private $redis ; private $channel_queue; private $current_index ; public function __construct() { $this-size 100; $this-redis new Redis(); $this-channel_queue staffs; $this-redis-connect(127.0.0.1, 6379); $this-set_index(); } public function set_index($index0){ $this-redis-set(current_index,$index); } public function en_queue($key,$value) { return $this-redis-rpush($this-channel_queue, $key) $this-redis-set($key,$value);; } public function is_empty(){ return $this-redis-lsize(admins)0; } public function is_full(){ return $this-redis-lsize($this-channel_queue) $this-size; } public function remove($value){ return $this-redis-lrem($this-channel_queue,$value); } public function get_list(){ return $this-redis-lrange($this-channel_queue,0,-1); } public function delete_key($key){ return $this-redis-delete($key); } public function get_value($key){ return $this-redis-get($key); } public function allocate_admin(){ $index $this-redis-get(current_index); $size $this-redis-lsize(admins); if($size 0){ return false; } if($index$size){ $key $this-redis-lindex(staffs,$index); if($this-redis-get($key)1){ $this-remove($key); return $key; } else { $this-redis-decr($key); $this-redis-incr(current_index); return $key ; } } else { $this-redis-set(current_index,0); $this-allocate_admin(); } } } 转载于:https://www.cnblogs.com/dawuge/p/9055564.html