定制 sokil/php-list 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sokil/php-list

最新稳定版本:0.0.7

Composer 安装命令:

composer require sokil/php-list

包简介

Lists

README 文档

README

Build Status Latest Stable Version Coverage Status Total Downloads Daily Downloads

Installation

You can install library through Composer:

{
    "require": {
        "sokil/php-list": "dev-master"
    }
}

Priority Map

Priority map allows you to specify priority of items and iterate through this list in order to priority.

Add elements to list with priority:

<?php

$list = new \Sokil\DataType\PriorityMap();
$list->set('key1', 'value1', 10);
$list->set('key2', 'value2', 100);

Get elements according to priority:

<?php
foreach($list as $key => $value) {
    echo $key . ' - ' . $value;
}

// this will print
//   key2 - value2
//   key1 - value1

Get element by key:

<?php

$list = new \Sokil\DataType\PriorityMap();
$list->set('key1', 'value1', 10);
$list->get('key1');

Weight List

Weight list allows you to specify values and relative weights, and randomly get value according to it's weight.

Imagine that we have three database servers with ip addresses: 10.0.0.1, 10.0.0.2 and 10.0.0.3. We want to balance connections between nodes with weights 60%, 30% and 10%. So most connections goes to server 10.0.0.1, than to 10.0.0.2 and than to 10.0.0.3.

<?php

$list = new \Sokil\DataType\WeightList([
    '10.0.0.1' => 60,
    '10.0.0.2' => 30,
    '10.0.0.3' => 10,
]);

$ipAddress = $list->getRandomValue();

Now we have address on every request relatively to it's weight.

统计信息

  • 总下载量: 740
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-25