horde/hashtable
Composer 安装命令:
composer require horde/hashtable
包简介
Hash table client library
README 文档
README
Key/Value store abstraction with driver-specific capabilities for Redis native data structures, cross-process locking and transparent serialization of mixed PHP values.
Interfaces
| Interface | Capability |
|---|---|
HashTable |
get/set/delete/exists with mixed values and optional TTL |
LockableHashTable |
Cross-process lock/unlock (Redis, Memcache) |
RedisHashTable |
Atomic counters, hashes, lists, sets, TTL introspection |
Drivers
| Driver | Implements | Backend |
|---|---|---|
Driver\Redis |
RedisHashTable |
ext-redis (preferred) or Predis ^3 |
Driver\Memcache |
LockableHashTable |
Horde\Memcache\MemcacheApi |
Driver\Memory |
HashTable |
In-process array (testing/development) |
Driver\NullDriver |
HashTable |
No-op (always misses) |
Installation
composer require horde/hashtable
For Redis (recommended):
# Preferred: C extension pecl install redis # Fallback: pure PHP composer require predis/predis:^3
Usage
use Horde\HashTable\Driver\Redis; use Redis as PhpRedis; $client = new PhpRedis(); $client->connect('127.0.0.1', 6379); $ht = new Redis(client: $client, prefix: 'myapp_'); // Basic key-value $ht->set('user:1', ['name' => 'Alice'], ttl: 3600); $data = $ht->get('user:1'); // returns array or null // Locking $ht->lock('user:1'); try { $ht->set('user:1', ['name' => 'Bob']); } finally { $ht->unlock('user:1'); } // Redis-native structures $ht->increment('counter'); $ht->listPush('queue', $job); $ht->hashSet('session:abc', 'last_access', time()); $ht->setAdd('tags:post:1', 'php', 'redis');
Horde Core Integration
When used inside a Horde application, you can obtain instances via dependency injection:
use Horde\HashTable\HashTable; use Horde\HashTable\LockableHashTable; use Horde\HashTable\RedisHashTable; // Any configured driver $ht = $injector->get(HashTable::class); // Only drivers with real cross-process locking $ht = $injector->get(LockableHashTable::class); // Full Redis power (counters, hashes, lists, sets) $ht = $injector->get(RedisHashTable::class);
Configuration is read from conf.php under the hashtable key by
Horde\Core\Factory\HashTableFactory.
Legacy API
The PSR-0 classes under lib/ (Horde_HashTable_Base, Horde_HashTable_Predis,
etc.) remain available for backward compatibility. New code should use the PSR-4
interfaces in src/. See doc/UPGRADING.md for migration
details.
License
LGPL-2.1-only — see LICENSE.
horde/hashtable 适用场景与选型建议
horde/hashtable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.38k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 horde/hashtable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 horde/hashtable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.38k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 14
- 依赖项目数: 5
- 推荐数: 4
其他信息
- 授权协议: LGPL-2.1-only
- 更新时间: 2023-10-26