PHPackages                             philipphermes/storage-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. philipphermes/storage-bundle

ActiveSymfony-bundle[Caching](/categories/caching)

philipphermes/storage-bundle
============================

A Symfony bundle that wraps Predis and exposes a StorageClient with essential storage operations, while still allowing direct access to the underlying client for advanced use cases.

0.1.1(3mo ago)01MITPHPPHP &gt;=8.3CI passing

Since Mar 14Pushed 3mo agoCompare

[ Source](https://github.com/philipphermes/storage-bundle)[ Packagist](https://packagist.org/packages/philipphermes/storage-bundle)[ RSS](/packages/philipphermes-storage-bundle/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (2)Dependencies (9)Versions (4)Used By (0)

Storage Bundle
==============

[](#storage-bundle)

[![CI](https://github.com/philipphermes/storage-bundle/actions/workflows/ci.yml/badge.svg)](https://github.com/philipphermes/storage-bundle/actions/workflows/ci.yml)[![PHP](https://camo.githubusercontent.com/9c50dc780fa576f5c39b4feff00c05345c1471be0808881a09e750b91220dc54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e332d3838393242462e737667)](https://php.net)[![Symfony](https://camo.githubusercontent.com/83755319468ce3a2da168fd9b106b0653015b7dd2a73aab726a053db26c850df/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73796d666f6e792d253345253344253230372e342d3838393242462e737667)](https://symfony.com)

A Symfony bundle that wraps Predis and exposes a StorageClient with essential storage operations, while still allowing direct access to the underlying client for advanced use cases.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
    - [Configuration Examples](#configuration-examples)
- [Usage](#usage)
    - [Basic Operations](#basic-operations)
    - [Batch Operations](#batch-operations)
    - [Delete Operations](#delete-operations)
    - [Key Management](#key-management)
    - [Counters](#counters)
    - [Scanning Keys](#scanning-keys)
    - [Direct Client Access](#direct-client-access)
- [Console Commands](#console-commands)
    - [Get Key Value](#read-storage-data)
    - [Clean Storage](#clean-storage)
- [Development](#development)

Requirements
------------

[](#requirements)

- PHP 8.3 or higher
- Symfony 7.4+ / 8.0+
- Redis or Valkey server

Installation
------------

[](#installation)

Install the bundle via Composer:

```
composer require philipphermes/storage-bundle
```

The bundle will be automatically registered in your Symfony application.

Configuration
-------------

[](#configuration)

Configure the Redis/Valkey connection in `config/packages/storage.yaml`:

```
storage:
  schema: tcp         # Connection schema (tcp, unix)
  host: localhost     # Redis host
  port: 6379          # Redis port
  path: ~             # Unix socket path (alternative to host/port)
  username: ~         # Redis username (optional)
  password: ~         # Redis password (optional)
  persistent: false   # Use persistent connection
```

### Configuration Examples

[](#configuration-examples)

**Standard TCP connection:**

```
storage:
  schema: tcp
  host: localhost
  port: 6379
```

**With authentication:**

```
storage:
  schema: tcp
  host: redis.example.com
  port: 6379
  username: myuser
  password: '%env(REDIS_PASSWORD)%'
```

**Unix socket:**

```
storage:
  schema: unix
  path: /var/run/redis/redis.sock
```

Usage
-----

[](#usage)

Inject the `StorageClientInterface` into your services:

```
use PhilippHermes\StorageBundle\Client\StorageClientInterface;

class MyService
{
    public function __construct(
        private StorageClientInterface $storage
    ) {}
}
```

### Basic Operations

[](#basic-operations)

#### Set and Get

[](#set-and-get)

```
// Store a string
$this->storage->set('user:name', 'John Doe');

// Store an array (automatically JSON encoded)
$this->storage->set('user:1', ['name' => 'John', 'email' => 'john@example.com']);

// Retrieve a value
$name = $this->storage->get('user:name'); // "John Doe"
$user = $this->storage->get('user:1');    // ['name' => 'John', 'email' => '...']

// Returns null if key doesn't exist
$missing = $this->storage->get('nonexistent'); // null
```

#### Set with Expiration

[](#set-with-expiration)

```
use PhilippHermes\StorageBundle\Client\StorageClient;

// Expire in 60 seconds
$this->storage->set(
    'session:token',
    'abc123',
    StorageClient::EXPIRE_RESOLUTION_EX,
    60
);

// Expire in 5000 milliseconds
$this->storage->set(
    'rate:limit',
    '100',
    StorageClient::EXPIRE_RESOLUTION_PX,
    5000
);
```

### Batch Operations

[](#batch-operations)

```
// Set multiple keys at once
$this->storage->setMultiple([
    'user:1' => ['name' => 'John'],
    'user:2' => ['name' => 'Jane'],
    'user:3' => ['name' => 'Bob'],
]);

// Get multiple keys
$users = $this->storage->getMultiple(['user:1', 'user:2', 'user:3']);
// Returns: ['user:1' => [...], 'user:2' => [...], 'user:3' => [...]]
```

### Delete Operations

[](#delete-operations)

```
// Delete a single key
$this->storage->delete('user:1');

// Delete multiple keys
$this->storage->deleteMultiple(['user:1', 'user:2', 'user:3']);
```

### Key Management

[](#key-management)

```
// Check if key exists
if ($this->storage->exists('user:1')) {
    // Key exists
}

// Get TTL in seconds (-1 = no expiry, -2 = doesn't exist)
$ttl = $this->storage->ttl('session:token');

// Set expiration on existing key
$this->storage->expire('user:1', 3600); // Expire in 1 hour

// Remove expiration from key
$this->storage->persist('user:1');
```

### Counters

[](#counters)

```
// Increment a counter
$views = $this->storage->increment('page:views');        // +1
$views = $this->storage->increment('page:views', 5);     // +5

// Decrement a counter
$stock = $this->storage->decrement('product:stock');     // -1
$stock = $this->storage->decrement('product:stock', 10); // -10
```

### Scanning Keys

[](#scanning-keys)

```
// Iterate through keys matching a pattern
foreach ($this->storage->scan('user:*', 100) as $keyBatch) {
    foreach ($keyBatch as $key) {
        echo "Found key: $key\n";
    }
}
```

### Direct Client Access

[](#direct-client-access)

For advanced operations not covered by the wrapper:

```
$client = $this->storage->getClient();
$client->lpush('queue:jobs', 'job1');
$client->rpop('queue:jobs');
```

Console Commands
----------------

[](#console-commands)

The bundle provides several console commands for managing and inspecting your Redis/Valkey storage.

### Read Storage Data

[](#read-storage-data)

Retrieve and display a key's value with info:

```
# Get a key values by keys
php bin/console storage:read --keys="user:1,user:2,..."

# Get a key values by pattern
php bin/console storage:read --pattern="user:*"

# Show info (TTL, type)
php bin/console storage:read --pattern="user:*" --info

# Limit
php bin/console storage:read --pattern="user:*" --limit=50 #Default 100
```

### Clean Storage

[](#clean-storage)

Delete all keys matching a pattern:

```
# Delete all keys (with confirmation)
php bin/console storage:clean

# Delete keys matching a pattern
php bin/console storage:clean --pattern="cache:*"

# Skip confirmation prompt
php bin/console storage:clean --force

# Custom batch size
php bin/console storage:clean --pattern="session:*" --batch=500
```

---

Development
-----------

[](#development)

### Static Analysis

[](#static-analysis)

```
vendor/bin/phpstan analyse --memory-limit=1G
```

### Testing

[](#testing)

```
docker compose up -d
```

```
vendor/bin/phpunit
```

With coverage report:

```
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html coverage-report
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance81

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

100d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/89180745?v=4)[Philipp](/maintainers/philipphermes)[@philipphermes](https://github.com/philipphermes)

---

Top Contributors

[![philipphermes](https://avatars.githubusercontent.com/u/89180745?v=4)](https://github.com/philipphermes "philipphermes (8 commits)")

---

Tags

redisstoragevalkey

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philipphermes-storage-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/philipphermes-storage-bundle/health.svg)](https://phpackages.com/packages/philipphermes-storage-bundle)
```

###  Alternatives

[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1615.6k12](/packages/2lenet-crudit-bundle)[web-auth/webauthn-framework

FIDO2/Webauthn library for PHP and Symfony Bundle.

51090.8k2](/packages/web-auth-webauthn-framework)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9317.2k55](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
