rkr/key-value-stores
Composer 安装命令:
composer require rkr/key-value-stores
包简介
Standard interfaces for common key-value-stores.
README 文档
README
This project aims to provide a standard interface to common key-value-stores like memcache, redis or similar. If an author of a specific driver develops against these interfaces, is can be used everywhere the interfaces are implemented. This project does not ship a concrete implementations to existing stores.
Common interfaces
Stores
The simple version of the key value stores provide methods to set, get and remove a entry. There is also a method to test if a entry is existing:
interface ReadWriteStore
public function has($key);
public function get($key, $default=null);
public function set($key, $value);
public function remove($key);
The ReadWriteStore-Interface has no own methods. It extends the 2 Interfaces ReadableStore and WritableStore which in turn extend from other, more basic interfaces. The idea behind this is described here.
Behavior of stores
has() returns true when a key exists in the store and false if not. In addition to that, it throws an exception when $key is not a valid type (see valid types).
get() returns the content of a entry, referenced by $key. If the entry was not found, get() then returns $default. $default must be a value value-type. In addition to that, an InvalidArgumentException or deriving gets thrown when $key is not a valid key-type (see valid types) and an InvalidOperationException or deriving gets thrown for store specific reasons.
set() sets the value of an entry. If the corresponding entry does not exist, set will create it. If the entry already exists, set will overwrite its content. set() returns $this for a fluent interface. In addition to that, an InvalidArgumentException or deriving gets thrown when $key is not a valid key-type (see valid types) and an InvalidOperationException or deriving gets thrown for store specific reasons.
remove() removes an entry from a store. It throws an InvalidOperationException or deriving if this operation fails, caused by a missing entry or another process failure. In addition to that, an InvalidArgumentException or deriving gets thrown when $key is not a valid key-type (see valid types).
Contexts
A context is similar to a table in a RDBMS. With contexts, you can separate stores for different environments or components. So a context is like a central singleton-repository for stores.
For example, a context could be used to define a database connection. Every store created by that context inherit that connection and possibly some metadata too.
Valid types
Valid key-type
A key is valid if it is a string, int or object with a __toString() method. The store must not serialize and/or hash a key to convert any object to a string.
Valid value-type
A value (or default-value) is valid under the same criterias as a key-type. A default-value is also allowed to be null.
Standard-tests
A store-author can make use of the provided standardtests to ensure compilance. So far, there are only tests for the ReadWriteStore and the Contexts. The tests are based in phpunit 3.7.
Installation via composer
composer require "rkr/php-key-value-stores" "~v0.0"
rkr/key-value-stores 适用场景与选型建议
rkr/key-value-stores 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 133 次下载、GitHub Stars 达 3, 最近一次更新时间为 2014 年 02 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rkr/key-value-stores 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rkr/key-value-stores 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 133
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 17
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-02-10
