定制 cesargb/key-value-store 二次开发

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

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

cesargb/key-value-store

Composer 安装命令:

composer require cesargb/key-value-store

包简介

A simple key-value store implementation in PHP.

关键字:

README 文档

README

A simple and flexible key-value store library for PHP. It provides a common API with multiple backends: in-memory array, file storage, Redis (ext-redis), Predis, and Eloquent.

Install

composer require cesargb/key-value-store

Requirements:

  • PHP ^8.4

Optional dependencies:

  • ext-redis for RedisStore
  • predis/predis for PredisStore
  • illuminate/database for EloquentStore
  • illuminate/support for Laravel service provider integration

Usage

List of stores

  • ArrayStore: in-memory storage (resets when process ends)
  • FileStore: file-based storage in a local directory
  • RedisStore: Redis storage using the ext-redis extension
  • PredisStore: Redis storage using predis/predis
  • EloquentStore: database storage through an Eloquent model

Basic usage

<?php

use Cesargb\KeyValueStore\Store;
use Cesargb\KeyValueStore\Repositories\ArrayStore;

$store = new Store(new ArrayStore());

$store->set('name', 'Cesar');
echo $store->get('name'); // Cesar

var_dump($store->has('name')); // true
$store->delete('name');
var_dump($store->has('name')); // false

Multiple keys

<?php

use Cesargb\KeyValueStore\Store;
use Cesargb\KeyValueStore\Repositories\ArrayStore;

$store = new Store(new ArrayStore());

$store->setMultiple([
    'a' => 1,
    'b' => 2,
]);

$values = $store->getMultiple(['a', 'b', 'c'], 'default');
// ['a' => 1, 'b' => 2, 'c' => 'default']

$store->deleteMultiple(['a', 'b']);

Use a different repository

<?php

use Cesargb\KeyValueStore\Store;
use Cesargb\KeyValueStore\Repositories\FileStore;
use Cesargb\KeyValueStore\Repositories\RedisStore;
use Cesargb\KeyValueStore\Repositories\PredisStore;
use Cesargb\KeyValueStore\Repositories\EloquentStore;

// File repository
$store = new Store(new FileStore(__DIR__.'/storage/kv'));

// Redis repository (ext-redis)
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$store = new Store(new RedisStore($redis, prefix: 'kv_'));

// Predis repository
$predis = new Predis\Client(['host' => '127.0.0.1', 'port' => 6379]);
$store = new Store(new PredisStore($predis, prefix: 'kv_'));

// Eloquent repository
// Uses package default model/table (key_value_store).
$store = new Store(new EloquentStore());

// Optional custom model (must have key + value columns).
$store = new Store(new EloquentStore($model));

Key rules:

  • Keys cannot be empty.
  • Keys cannot contain: { } ( ) / \ @ :

Laravel integration

The package includes Cesargb\KeyValueStore\Laravel\KeyValueStoreServiceProvider with auto-discovery support.

Publish assets:

php artisan vendor:publish --tag=key-value-store-config
php artisan vendor:publish --tag=key-value-store-migrations
php artisan migrate

Publishing is only registered when the application is running in console, and the migration is published with a current timestamped filename.

Resolve from container:

<?php

use Cesargb\KeyValueStore\Contracts\Store as StoreContract;

$store = app(StoreContract::class);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固