simpletools/db-indexedfile
Composer 安装命令:
composer require simpletools/db-indexedfile
包简介
High-throughput non-concurrent NoSQL key-value file-based database with a memory-backed index.
关键字:
README 文档
README
IndexedFile is a DB system allowing to very quickly process and store big amount of data by leveraging memory as an index while keeping all the other data on disk with high-throughput read and write engine.
To simplify snippets below, its assumed that the following namespaces are in use:
use \Simpletools\Db\IndexedFile;
Initialise Temp DB
To start a new temp DB which will get removed when the script terminates:
$indexedFile = new IndexedFile\File();
Initialise from existing DB
To start DB which might have already exists or which should persist after script terminate:
$indexedFile = new IndexedFile\File('/path/to/my/db.jsonl');
Setup a custom IndexStore
You can write your own IndexStore which implements IndexStoreInterface and preset it with the following static method:
//the default IndexStore IndexedFile\File::indexStoreClass('Simpletools\Db\IndexedFile\IndexStore\ArrayIndexStore');
Storing data
Inserting/Replacing data by key
$indexedFile->insert('key',["foo"=>"bar"]);
Storing data if not exists
Ignoring insert if key already exists
$indexedFile->insertIgnore('key',["foo"=>"bar"]);
Reading data
Reading by key
$value = $indexedFile->read('key');
Iterating through all entries
Iterating through all entires
foreach($indexedFile->iterate() as $key => $value) { var_dump($key,$value); }
Upserting data
Updating/Inserting your data
$indexedFile->upsert('key',function($row){ if($row) { $row->counter++; return $row; } else { return [ 'counter' => 0 ]; } });
Removing data
Removing a key
$indexedFile->remove('key');
Truncating database
Removing all entires
$indexedFile->truncate();
or when booting up
$indexedFile = new IndexedFile\File('/path/to/my/db.jsonl',true);
Sorting
Declare text sort
$indexedFile->sort('title','ASC', 'string');
Declare integer sort
$indexedFile->sort('count','DESC', 'int');
includeSortStats flag adds to the indexed object _sort meta field with position in sort and percent of total (integer only)
$indexedFile->sort('count','DESC', 'int', true);
Own input and output files
$indexedFile->sort('title','ASC', 'string',true, __DIR__.'/unsorted.csv', __DIR__.'/sorted.csv');
Example of use for sorting by price and list with an iterator
$indexedFile->sort('price','DESC', 'int'); $indexedFile->insertIgnore($data['id'],[ 'title' => $data['title'], 'price' => $data['price'] ]); $indexedFile->runSort(); foreach ($indexedFile->sortIterate() as $groupId => $row) { echo 'Position: '. $row->_sort->position.' Percent: '.$row->_sort->position.' Index key: '. $groupId .' Price: '. $row->price."\n"; }
simpletools/db-indexedfile 适用场景与选型建议
simpletools/db-indexedfile 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.93k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 08 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 simpletools/db-indexedfile 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 simpletools/db-indexedfile 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 simpletools/db-indexedfile 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
High-performance, opinionated PHP 8 web framework with O(1) routing, parallel async MySQL, type-safe asset bridge, and React-island frontend
The skeleton application for the Geoffrey agent framework.
Framework used for the Darflen social media project.
Speedrunner package for programming certification exam
Micro-framework PHP enxuto e modular: ORM, Router, Auth, Validation, Security, Container, View, Queue, Console e Schema.
统计信息
- 总下载量: 3.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2021-08-08