talleu/php-redis-om 问题修复 & 功能扩展

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

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

talleu/php-redis-om

最新稳定版本:v0.4.5

Composer 安装命令:

composer require talleu/php-redis-om

包简介

A PHP object mapper library for Redis

README 文档

README

Build Status PHPStan Packagist Version GitHub codecov.io Code Coverage

php-redis-om ????️

A PHP object mapper for Redis.

An Object Mapper for Redis®, designed to providing an intuitive and familiar interface for PHP developers to interact with Redis.

Features ????️

  • Doctrine-like methods and architecture
  • Symfony bundle integration
  • Easy integration with existing PHP applications
  • High performance and scalability with Redis®
  • Support for Redis JSON module
  • Automatic schema generation
  • Search and query capabilities
  • Auto-expiration of your objects
  • API Platform support (beta)

Requirements ⚙️

  • PHP 8.2 or higher
  • Redis 4.0 or higher
  • Redisearch module (available by default with Redis >8 or in redis-stack distribution) (installation)
  • php-redis extension OR Predis library
  • Redis JSON module (optional, include in redis-stack)
  • Composer

Supported types ✅

  • scalar (string, int, float, bool, double)
  • timestamp
  • json
  • null
  • DateTimeImmutable
  • DateTime
  • array and nested arrays
  • object and nested objects
  • stdClass

Installation ????

Install the library via Composer:

composer require talleu/php-redis-om

Depending on your configuration, use phpredis or Predis

Symfony bundle ????

In a Symfony application, you may need to add this line to config/bundles.php

 Talleu\RedisOm\Bundle\TalleuRedisOmBundle::class => ['all' => true],

And that's it, your installation is complete ! ????

API Platform support ????️

For API Platform users, a basic implementation is provided here: API Platfom X Redis

Basic Usage ????

Add the RedisOm attribute to your class to map it to a Redis schema:

<?php use Talleu\RedisOm\Om\Mapping as RedisOm; #[RedisOm\Entity] class User { #[RedisOm\Id] #[RedisOm\Property] public int $id; #[RedisOm\Property(index:true)] public string $name; #[RedisOm\Property] public \DateTimeImmutable $createdAt; }

After add the RedisOm attribute to your class, you have to run the following command to create the Redis schema for your classes (default path is ./src):

For Symfony users:

bin/console redis-om:migrate 

For others PHP applications:

vendor/bin/redisMigration <YOUR DIRECTORY PATH>

Then you can use the ObjectManager to persist your objects from Redis ! ????

For Symfony users, just inject the RedisObjectManagerInterface in the constructor:

<?php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Talleu\RedisOm\Om\RedisObjectManagerInterface; use App\Entity\Book; class MySymfonyController extends AbstractController { public function __construct(private RedisObjectManagerInterface $redisObjectManager) {} #[Route('/', name: 'app_home')] public function index(): Response { $book = new Book(); $book->name = 'Martin Eden'; $this->redisObjectManager->persist($book); $this->redisObjectManager->flush(); //.. } }

For others PHP applications:

<?php use Talleu\RedisOm\Om\RedisObjectManager; $user = new User() $user->id = 1; $user->name = 'John Doe'; // Persist the object in redis $objectManager = new RedisObjectManager(); $objectManager->persist($user); $objectManager->flush();

???? Congratulations, your PHP object is now registered in Redis !

You can now retrieve your user wherever you like using the repository provided by the Object Manager (or the object manager directly):

// Retrieve the object from redis  $user = $this->redisObjectManager->find(User::class, 1); $user = $this->redisObjectManager->getRepository(User::class)->find(1); $user = $this->redisObjectManager->getRepository(User::class)->findOneBy(['name' => 'John Doe']); // Retrieve a collection of objects $users = $this->redisObjectManager->getRepository(User::class)->findAll(); $users = $this->redisObjectManager->getRepository(User::class)->findBy(['name' => 'John Doe'], ['createdAt' => 'DESC'], 10);

Advanced documentation ????

统计信息

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

GitHub 信息

  • Stars: 195
  • Watchers: 5
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固