junker/hsal 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

junker/hsal

Composer 安装命令:

composer require junker/hsal

包简介

HandlerSocket Abstraction layer

README 文档

README

Build Status Latest Stable Version Total Downloads Scrutinizer Code Quality License

HSAL - HandlerSocket Abstraction Layer library for PHP

Requirements

HSAL requires PHP 5.4 or later.

one of handlerSocket Libraries:

Installation

The best way to install HSAL is to use a Composer:

php composer.phar require junker/hsal

Examples

use HSAL\HSAL;

$hs = new HSAL('localhost', 'database');

//SELECT id,title FROM pages WHERE id=5
$page = $hs->fetchAssoc('pages', 
	['id', 'title'], 
	[HSAL::INDEX_PRIMARY => 5]
); 
print_r($page); // ['id' => 5, 'title' => 'page number 5']
//SELECT title FROM pages WHERE id=5
$title = $hs->fetchColumn('pages', 'title', [HSAL::INDEX_PRIMARY => 5]); 
print_r($title); // page number 5
//SELECT id,page_id,title FROM pages_lang WHERE page_id=5 AND language_id=2
$page = $hs->fetchArray('pages_lang', 
	['id', 'page_id', 'title'], 
	['page_lang' => [5,2]]
); 
print_r($title); // [21, 5, 'numéro de la page 5']
//SELECT id,title FROM pages WHERE view_count>10 LIMIT 5
$pages = $hs->fetchAll('pages', 
	['id', 'title'], 
	['view_count' => 10], 
	HSAL::OPERATOR_GREATER, 
	5
); 
print_r($pages); 
// [['id' => 4, 'title' => 'page number 4'], ['id' => 5, 'title' => 'page number 5']] 
//can make request to another database(i.e. dev_database) without creating new HSAL instance
//SELECT title FROM dev_database.pages WHERE id=5
$title = $hs->fetchColumn('dev_database.pages', 'title', [HSAL::INDEX_PRIMARY => 5]); 
use HSAL\HSAL;

$hs = new HSAL('localhost', 'database', ['driver' => HSAL::DRIVER_HSPHP, 'port_write' => 5555]);

$hs->insert('pages', ['id' => 6, 'title' => 'New page']);

$result = $hs->delete('pages', ['id' => 6]);
print_r($result); // 1
$result = $hs->delete('pages', ['id' => 6]);
print_r($result); // 0, because record doesn't exists

$hs->update('pages', ['title' => 'Best page'], [HSAL::INDEX_PRIMARY => 5]);

$hs->increment('pages', 'view_count', [HSAL::INDEX_PRIMARY => 5]);

API

Methods

__construct($host, $database, $options)

name description type
host ip or hostname of HandlerSocket server string, required
database database name string, required
options array of options assoc array, optional
Options:
  • driver: default HSAL::DRIVER_AUTO
  • port_read: read port (int)
  • port_write: write port (int)
  • timeout: timeout, works only for Handlersocketi driver (double, default: 5)
  • rw_timeout: read/write timeout, works only for Handlersocketi driver (double, default: 5)

fetchArray($table, $fields, $index_condition, $operator)

name description type
table table name string, required
fields requested fields array, required
index_condition query condition assoc array, required
operator operator for query condition optional, default: HSAL::OPERATOR_EQUAL

fetchAssoc($table, $fields, $index_condition, $operator)

name description type
table table name (string, required)
fields requested fields array, required
index_condition query condition assoc array, required
operator operator for query condition optional, default: HSAL::OPERATOR_EQUAL

fetchColumn($table, $field, $index_condition, $operator)

name description type
table table name string, required
field requested field string, required
index_condition query condition assoc array, required
operator operator for query condition optional, default: HSAL::OPERATOR_EQUAL

fetchAll($table, $fields, $index_condition, $operator, $limit, $offset)

name description type
table table name string, required
fields requested field string, required
index_condition query condition assoc array, required
operator operator for query condition optional, default: HSAL::OPERATOR_EQUAL
limit limit rows int, optional, default: 1000
offset offset int, optional, default: 0

delete($table, $index_condition, $operator)

name description type
table table name string, required
index_condition query condition assoc array, required
operator operator for query condition optional, default: HSAL::OPERATOR_EQUAL

insert($table, $values)

name description type
table table name string, required
values array of fields with values assoc array, required

update($table, $values, $index_condition, $operator)

name description type
table table name string, required
values associative array of fields with values assoc array, required
index_condition query condition assoc array, required
operator operator for query condition optional, default: HSAL::OPERATOR_EQUAL

increment($table, $field, $index_condition, $operator, $increment)

name description type
table table name string, required
field requested field string, required
index_condition query condition assoc array, required
operator operator for query condition optional, default: HSAL::OPERATOR_EQUAL
increment increment value int, optional, default: 1

decrement($table, $field, $index_condition, $operator, $decrement)

name description type
table table name string, required
field requested field string, required
index_condition query condition assoc array, required
operator operator for query condition optional, default: HSAL::OPERATOR_EQUAL
decrement decrement value int, optional, default: 1
//Operators
HSAL::OPERATOR_EQUAL = '=';
HSAL::OPERATOR_LESS = '<';
HSAL::OPERATOR_LESS_EQUAL = '<=';
HSAL::OPERATOR_GREATER = '>';
HSAL::OPERATOR_GREATER_EQUAL = '>=';

//Drivers
HSAL::DRIVER_AUTO //auto-detect
HSAL::DRIVER_HSPHP
HSAL::DRIVER_HANDLERSOCKETI

Roadmap

junker/hsal 适用场景与选型建议

junker/hsal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 84 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 01 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「nosql」 「database」 「dbal」 「mysql」 「handler socket」 「mariadb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 junker/hsal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 junker/hsal 我们能提供哪些服务?
定制开发 / 二次开发

基于 junker/hsal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-23