2017 © Pedro Pelรกez
 

symfony-bundle dark-redis-list-bundle

Symfony2 bundle which allows you to store part of doctrine entities data in Redis.

image

cursedcoder/dark-redis-list-bundle

Symfony2 bundle which allows you to store part of doctrine entities data in Redis.

  • Tuesday, March 12, 2013
  • by dark
  • Repository
  • 2 Watchers
  • 5 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

DarkRedisListBundle Build Status

Symfony2 bundle which allows you to store part of doctrine entities data in Redis. For more information please read text below., (*1)

How do we manage lists at MySQL:

  • write query, for example 'SELECT a FROM MyTestBundle:Post a ORDER BY a.created_at'
  • use doctrine repository

then we can pass it to the paginator, but no need to talk about it now., (*2)

But I need more functionality to those lists:

  • combine few entity types at one list\query
  • retrieve real-time result
  • use permanent cache for each entitiy
  • it's should be fast

Introducing to Redis Lists

Redis List โ€” it's structured data, that is stored in Redis hashes (do not confuse native Redis lists with ours). Okay, let's learn more about this., (*3)

What Redis List is?

Each list have name, for example โ€” 'View', each element of this hash has unique ID and it contains some value., (*4)

Here is example of Redis List:, (*5)

Hash  ID   Value
View โ€” 1 โ€” SonataBadBundle:Post;1
View โ€” 2 โ€” SonataBadBundle:Post;2
View โ€” 3 โ€” SonataBadBundle:Post;3
View โ€” 4 โ€” KnpGoodBundle:Article;1
View โ€” 5 โ€” MyPromoBundle:Promo;1

So, as you can see that each hash: - starts from 1 id - all ids are holistic (count of all elements = last element id), (*6)

Okay, but how it's can satisfy my requirements?, (*7)

Each element of Redis List contains information about entities โ€” repository name, id.
I can fetch those entities through repository, and then cache it in Memcached for example.

Features which it gives to you:

  • real-time list result
  • can store entities in cache permanently
  • if new element passed to list, no need to reload old entities from DB
  • it allows to list a few types of entities as one list
  • it allows to list random entities from list freely, cuz ids are holistic, and also no need to fetch them from DB

Installation

Add DarkRedisListBundle in your composer.json, (*8)

{
    "require": {
        "cursedcoder/dark-redis-list-bundle": "*"
    }
}

Register the bundle in your app/AppKernel.php:, (*9)

<?php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Dark\RedisListBundle\DarkRedisListBundle(),
    );
)

Collectors

  • Single โ€” fetches entities one at a time (1 request per entity)
  • Pieces โ€” fetches entities by pieces, for example for list "Post1, Post2, Answer1, Answer2, Post3, Post4" it will take 3 requests

Listener

Redis listener is automatically loads Redis-data to your entities. It is enabled by default., (*10)

Configuration reference

# app/config.yml
dark_redis_list:
    collector: single # or pieces
    template: DarkRedisListBundle:Pagination:list.html.twig
    time: 604800 # cache lifetime, 0 by default
    use_listener: true

Credits

I wrote this bundle for my own needs, so don't angry if anything will going not good :P, (*11)

The Versions

12/03 2013

dev-master

9999999-dev http://github.com/cursedcoder/DarkRedisListBundle

Symfony2 bundle which allows you to store part of doctrine entities data in Redis.

  Sources   Download

MIT

The Requires

 

redis doctrine list cursedcoder