snc / sncredisbundle Goto Github PK
View Code? Open in Web Editor NEWA Redis bundle for Symfony supporting Predis and PhpRedis
Home Page: https://github.com/snc/SncRedisBundle
License: MIT License
A Redis bundle for Symfony supporting Predis and PhpRedis
Home Page: https://github.com/snc/SncRedisBundle
License: MIT License
I was wondering if you are accepting pull requests implementing commands of specific redis commands (like flushdb). I implemented it in a very easy way because I need it for my functional tests (reseting redis so I run the tests on a clean database).
If so, I would do a pull request for the flushdb command and others if I happen to write more (or if anyone else needs some!).
Hi,
In this commit predis has been moved to be only in the dev deps list, this to me seems quite silly because predis is the main component this bundle is based of.
When I did a "composer.phar update" it failed to install predis and the bundle is effectively void.
Is there any reasoning behind this move? If I have to use the --dev param for a reason I'm not aware of then thats cool as well.
reference: 656cc63#L3R22
thanks
Hi Henrik,
I was about to submit a pull request to add a composer.json
file so that you can publish your bundle onto Packagist and people can start using Composer to manage their dependencies, but I noticed that there are no tagged versions of RedisBundle and the license doesn't seem to be specified anywhere (I guess it's MIT since Symfony2 and Predis are both released under that license, but it's just my assumption).
It's not really mandatory to tag a stable version, so you can declare a development one without tagging it onto Git (just like I did with Predis, which is published using the master branch under the 0.7.0-dev
nomenclature but has no tags yet) that will be tagged once Symfony2 and/or Predis are released as stable.
What do you think about it?
Hi,
Predis library provides the ability to define custom (scripted) commands.
From the documentation it is needed to do:
$client->getProfile()->defineCommand('lpushrand', 'ListPushRandomValue');
Obviously, this is not straight-forward in the context of a Symfony2 application.
I couldn't find any trace in the bundle code to support this, and if I'm right I would be happy to implement it myself to allow to define commands in configuration.
I'm just starting with Redis and friends, but a configuration could look like:
snc_redis:
clients:
default:
type: predis
alias: default
dsn: redis://localhost
custom_commands:
lpushrand:
class: My\Redis\Command\ListPushRandomValue
Some questions remain though:
phpredis
Any feedbacks?
Hi,
we're trying to store the Symfony sessions using redis. This works fine so far with the handler provided by this bundle, but we'd need to serialize/deserialize the session data using json, not as a serialized php array.
The reason is that a websocket running node.js needs to access the php sessions, so it would be easier to use json as serialization format.
Anyone a hint how to do this?
Hi, It would be great to have a way to easily disable doctrine and session support when running tests without having to remove the config from the config.yml file. Would it be possible to add a disabled flag or someting like that to the doctrine part of the config?
https://github.com/snc/SncRedisBundle/blob/master/DependencyInjection/SncRedisExtension.php#L257
This line says that if logging is enabled you will get Snc\RedisBundle\Client\Phpredis\Client instance, otherwise the \Redis instance will be given to snc_redis.default service.
If you'll try to write
function __construct(Client $redis) { ... }
and then set "logging: %kernel.debug%" in the client config, it'll be ok in dev, but if you'll try to clear prod cache you'll get an exception. But in case of Predis you'll always get Predis\Client instance.
See http://symfony.com/blog/upgrading-your-symfony-projects-the-easy-way
"As of Symfony 2.3, the minimum stability level has been raised to stable. That was possible because the Symfony ecosystem as a whole is much more mature and because almost all good/useful/maintained/popular bundles have stable releases with a good configuration for their dependencies. If you know of a cool bundle or PHP library that still requires a dev minimum stability, talk to the lead developer and convince him to tag a stable release."
Hi,
It seems to me that line 154 in SncRedisExtension should read:
$profileDef = new Definition(get_class(\Predis\Profiles\ServerProfile::get($client['options']['profile'])));
In your code, it has \Predis\Profile, instead of Profiles.
Hope this helps,
Hello,
I would like to add the ability to set TTL on Redis session keys, but without having to set the cookie_lifetime
option of the framework.
The reason is that setting an expiration date on the session cookie could be a bad idea. For instance, a client who have an "early date" (in GMT -- many people change the time of their computer without selecting the right timezone) will not have any session because his browser will consider the cookie expired.
For that reason I prefer to leave the cookie_lifetime to 0. But I still want to set a TTL in redis (for security and storage purposes). As this StackOverflow comment points out, a "timeout should be implemented on your own", not with session.gc_maxlifetime
or session.cookie_lifetime
.
So the idea is to add a parameter in the configuration which will override the cookie_lifetime parameter of the framework config. Something like:
snc_redis:
...
session:
client: session
prefix: foo
cookie_lifetime: 1440 # override framework.cookie_lifetime for Redis TTL
I would like your opinion before implementing this solution.
After the recent upgrade, configuration merges do not happen like they used to. I have a default config.yml
like this:
snc_redis:
clients:
default:
type: predis
alias: default
dsn: %redis.default.dsn%
logging: %kernel.debug%
And what used to be an override in config_test.yml
like this:
snc_redis:
clients:
default:
dsn: %redis.test.dsn%
However, this converts my dsn
override into an array of dsns
, rather than obeying that I want the dsn
overwritten.
Can the bundle allow for an exception to be thrown so that Symfony can deal with redis servers not being available gracefully.
We use redis for caching - so in the event of the back end redis server not being available - we can still generate the content rather than returning a 500 server error
Hi,
I know this isn't an issue but I was wondering if you could add support for caching doctrine mongodb metadata.
Thanks
Daniel
Can you update to support doctrine2 master?
PHP Fatal error: Class Snc\RedisBundle\Doctrine\Cache\RedisCache contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Doctrine\Common\Cache\Cache::getStats) in Snc/RedisBundle/Doctrine/Cache/RedisCache.php on line 237
Hi,
I've just setup the session handling as instructed inside the documentation.
Even though I've called session set etc, my redis db has no keys inside it when I dump the contents of it, making me believe that the session data isn't really being stored inside redis.
The 'RedisSessionHandler' constructor appears to be called, but even if i put an exit statement inside the 'read' method it never appears to be reading the session data from redis.
If you can please confirm that it should actually be working with the current symfony2 master repository that would be much appreciated.
Cheers
It throws an exception: The child node "clients" at path "snc_redis" must be configured.
I have done all in the Installation part. What is the reason?
Not sure if this is expected behavior, something I am doing wrong, or what... I have a service where I inject redis and when it is in dev mode the object is of type \Snc\RedisBundle\Client\Phpredis\Client but in prod mode it is of type \Redis. So I can't use type hinting in the service constructor.
My configs are below:
snc_redis:
clients:
cache:
type: phpredis
alias: cache
dsn: redis://localhost
logging: %kernel.debug%
session:
client: cache
prefix: sessions
use_as_default: true
acme.teams_recent:
class: Acme\TeamBundle\Service\RecentTeams
arguments: [@snc_redis.cache]
I have a question on the status of this bundle https://github.com/snc/SncRedisBundle
The tag build-failing an explicit non-operation of the release?
my conf:
snc_redis:
clients:
default:
type: phpredis
alias: default
dsn: redis://127.0.0.1:6379/1
logging: %kernel.debug%
cache:
type: phpredis
alias: cache
dsn: redis://127.0.0.1:6379/2
session:
type: phpredis
alias: session
dsn: redis://127.0.0.1:6379/3
session:
ttl: 3600
client: session
prefix: sc_session
use_as_default: true
framework:
session: ~
my controller:
/**
* @Route("/about",name="aboutMe")
* @Template()
*/
public function meAction()
{
$v=rand(1,9999);
ld($v);
$this->get('session')->set('aaaaaaaaa',$v);
return new \Symfony\Component\HttpFoundation\RedirectResponse('/advice');
}
/**
* @Route("/advice",name="aboutAdvice")
* @Template()
*/
public function adviceAction()
{
ld($this->get('session')->get('aaaaaaaaa'));
return array('title' => 'aaa');
}
so what I did is:
1.generate a random number on page A
2.dump the number
3.Save the number into session on page A
4.redirect to Page B
5.dump the number which has been saved into session on page A
Normally, I will get 2 same number on page A and page B
but,some times, I will get the different number on Page B which has been save on last turn on Page A.
I guess the problem is because the save function of session hasn't been called automatically.
When I try to run the flush:command on Symfony2.0.16 I get the following error:
[LogicException]
An option named "no-interaction" already exist.
Solution: Remove the no-interaction option. Symfony add's it later anyway.
Hello,
I saw another bug with the session_cookie fix : when the option cookie_lifetime is not configured in config.yml, the default configuration is not setted in the $options array like previous version. An undefined index error appears here : https://github.com/snc/SncRedisBundle/blob/master/SessionStorage/RedisSessionStorage.php#L81
Maybe you can add a condition to check if the option exists.
Sorry, i hadn't noticed this bug before you commit my next issue.
When I call app/console assets:install ...
, an attempt is made to connect to the Redis server, but at this stage of my deployment process the web and caching servers aren't connected. I'm not sure what reason is there for there to be any connection made when running that command but by removing metadata_cache
from my config I was able to execute the command.
snc_redis:
clients:
default:
type: predis
alias: default
dsn: %redis_dsn%
cache:
type: predis
alias: cache
dsn: %redis_doctrine_dsn%
options:
profile: 2.2
connection_timeout: 10
read_write_timeout: 30
doctrine:
# metadata_cache:
# client: cache
# entity_manager: default
result_cache:
client: cache
entity_manager: default
namespace: "dcrc:"
query_cache:
client: cache
entity_manager: default
Hi,
Currently I am using SncRedisBundle for session storing,
and when I excute unit test, I want to have session storing in files just as previous settings,
how do I disable redis for unit test? thanks in advanced.
There is a userResultCache method in EntityManager(ORM), but I can't find any way of using result cache in a DocumentManager(ODM)
Hello,
The index "lifetime" in RedisSessionStorage (https://github.com/snc/SncRedisBundle/blob/master/SessionStorage/RedisSessionStorage.php#L81) must be renamed by "cookie_lifetime" because there is a bug in Symfony about this feature (see: symfony/symfony#3423)
Thanks !
Can you add support for doctrine 2.3 for the cache adapters? The interface has changed..
Running app/console doctrine:cache:clear-metadata
throws the following exception if cache is empty:
[Predis\ServerException]
ERR wrong number of arguments for 'del' command
I get the following errors when trying to use the bundle with phpredis:
[09-Aug-2012 08:23:59 UTC] PHP Warning: Redis::pipeline() expects exactly 0 parameters, 1 given in /var/.../bundles/Snc/RedisBundle/Client/Phpredis/Client.php on line 82
[09-Aug-2012 08:23:59 UTC] PHP Catchable fatal error: Object of class Closure could not be converted to string in /var/.../bundles/Snc/RedisBundle/Client/Phpredis/Client.php on line 101
Symfony2.0
php -v:
PHP 5.3.15-1~dotdeb.0 with Suhosin-Patch (cli) (built: Jul 23 2012 13:30:08)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH
Hi, I'm using SNC Redis with multiple connections - default is for things I care about, while cache is for things that may die.
Now, my problem is that when I use the default connection (blocking on blpop) together with a second connection for the cache, the cache blows up when blpop returns and I start using the cache since the cache connection has timed out.
Should I use connection_persister:true here or is there another parameter I should use ?
Which will result in this package not be usable @SF2-Master.
Hello
i wanna using SncRedisBundle to cache doctrine result cache on redis server;
This is my config:
config.yml:
snc_redis:
connections:
default:
alias: default
host: %redis_host%
port: %redis_port%
database: 0
session:
alias: session
host: %redis_host%
port: %redis_port%
database: 0
clients:
default:
alias: default
connection: default
session:
alias: session
connection: session
config_dev.yml :
snc_redis:
session:
client: session
doctrine:
result_cache:
client: default
entity_manager: default
I found result_cache always can not cache on redis server.
But session and query_cache can cache on redis server.
Have i missed some config to config_dev.yml?
We are using redis for caching - it would be very useful to be able to specify the ttl for the cache in the redis config. I see it has been added to session configs - is it possible to add it for other configs.
A good thing on this bundle would be to implement an anti dog-pile system as described here : https://github.com/LeaseWeb/LswMemcacheBundle#adp-anti-dog-pile
It would be really cool for high traffic website !
Thanks in advance.
I was receiving this error whenever deleting objects from the cache by prefix (deleteByPrefix). apparently, if there are no matching objects, this error comes up.
I fixed this by changing the function from:
public function deleteByPrefix($prefix)
{
$deleted = $this->getIds($prefix);
return $deleted;
}
to:
public function deleteByPrefix($prefix)
{
$deleted = $this->getIds($prefix);
if(count($deleted))
{
$this->_doDelete($deleted);
}
return $deleted;
}
Are there any best practices how to write tests that use redis? i'm having a couple of events in my application that write to redis, and when those events are triggered in other tests, the entries are created in the real redis instance.
Should we setup a second instance and configure our app to use a test-instance when running tests?
Should be great create a library with ..\Client directory
in order to have a single Client for PHPRedis and predis , that could be used from other projects.
What do you think?
Hi
I tried to use the session storage but it's not working at all
-Code: master branch
-Server : Apache or nginx + fpm
I have a redis cluster (implementing client-side sharding). The configuration is something like the following:
snc_redis:
clients:
lock:
type: predis
alias: lock
dsn:
- redis://localhost/1?weight=10
- redis://localhost/2?weight=5
- redis://localhost/3?weight=3
- redis://localhost/4?weight=3
After activating this, I am getting the following error:
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
The service definition "snc_redis.client.lock1_options" does not exist.
The bug seems to be in the LoggingPass compiler pass.
I tried to fix the bug and make a PR, but do not understand what is the purpose of the compiler pass and how to handle Loggable connections when multiple servers are defined.
Could you please give some insights so that I could work on a patch.
Thanks.
Hi
I am trying to get redis to store my session data. I have the following configuration
snc_redis:
clients:
default:
type: predis
alias: default
dsn: redis://localhost
session:
type: predis
alias: session
dsn: redis://localhost/2
session:
client: session
prefix: session_
use_as_default: true
but it does not work i.e there are no keys in database 2 in redis.
I also tried setting
session:
storage_id: snc_redis.session.handler
but I get the following fatal.
ErrorException: Catchable Fatal Error: Argument 1 passed to Symfony\Component\HttpFoundation\Session\Session::__construct() must implement interface Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface, instance of Snc\RedisBundle\Session\Storage\Handler\RedisSessionHandler
I am using
Symfony 2.1.3
"snc/redis-bundle": "2.1.x-dev",
"predis/predis": "0.8",
Any help in the right direction would be very welcome. Thanks
Hi,
I'm new to Redis and i'm trying to use SncRedisBundle.
Currently, i'm able to to store simple values in Redis (like strings or numbers) but, i'm not able to use Redis to cache some Doctrine queries.
Could you please provide me an example explaining how to store, for example a "findAll()" call into Redis?
I'm also looking for best practices to use Redis as good as possible.
Thanks for your help.
When doing lots of redis commands in a script, the memory overflow with approx 2-3mb per 1000 EXISTS commands.
I guess this is some kind of local caching behaviour .. is it possible to disable this by config?
Hi,
At this moment, we can define prefix on phpredis connection or predis but it's not work (at least for phpredis).
I guess we could only use:
snc_redis:
clients:
default:
type: predis
alias: default
dsn: redis://localhost
options:
prefix: XYZ
And then remove prefix notion on session.handler and namespace notion on doctrine.
phpredis
provides an option to define a prefix: https://github.com/nicolasff/phpredis#setoption
predis
too (i'm not sure it's implemented yet on this bundle).
Any thoughts ?
The interface has changed in predis:
Fatal error: Declaration of Snc\RedisBundle\Client\Predis\ConnectionFactory::create() must be compatible with that of Predis\ConnectionFactoryInterface::create() in vendor/bundles/Snc/RedisBundle/Client/Predis/ConnectionFactory.php on line 19
PHP Fatal error: Class 'Symfony\Component\HttpFoundation\Session\Storage\AbstractSessionStorage' not found in src/vendor/bundles/Snc/RedisBundle/SessionStorage/RedisSessionStorage.php on line 25
extends AbstractSessionStorage implements \SessionHandlerInterface
Should be extends NativeSessionHandler implements \SessionHandlerInterface
See:
When i try to load redis up using this :
var_dump($this->container->get('snc_redis.default_client'));
i get the following error :
Undefined property: Stockopedia\DemoBundle\Command\CacheRedisCommand::$container
CacheRedisCommand extends ContainerAwareCommand
I try to install SncRedisBundle via composer, so i added
composer.json:
"snc/redis-bundle": "dev-master"
config.xml:
snc_redis:
clients:
default:
type: predis
alias: default
dsn: redis://localhost
and i get this error:
InvalidArgumentException: There is no extension able to load the configuration for "snc_redis" (in app/config/config.yml). Looked for namespace "snc_redis", found "framework", "security", "twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", "jms_aop", "jms_di_extra", "jms_security_extra", "jms_serializer", "beryllium_cache", "gift_general", "acme_demo", "web_profiler", "sensio_distribution"
Hi,
How I can configure SensioLabsInsight to be bootable with this bundle and PHPRedis ?
I obained this error:
Fatal error: Class 'Redis' not found in /home/foobar/code/app/cache/prod/appProdProjectContainer.php on line 2175
I had proved to add this configuration but not works:
php_ini: |
extension=redis.so
Thanks
When I view the logger's output in FirePHP, I see the following
snc_redis: Executing command "GET foo"
But the codebase for the RedisLogger
class has the following
/**
* Logs a command
*
* @param string $command Redis command
* @param float $duration Duration in milliseconds
* @param string $connection Connection alias
* @param bool|string $error Error message or false if command was successful
*/
public function logCommand($command, $duration, $connection, $error = false)
{
++$this->nbCommands;
if (null !== $this->logger) {
$this->commands[] = array('cmd' => $command, 'executionMS' => $duration, 'conn' => $connection, 'error' => $error);
if ($error) {
$this->logger->err('Command "' . $command . '" failed (' . $error . ')');
} else {
$this->logger->info('Executing command "' . $command . '"');
}
}
}
$duration
variable being passed to this function if its not being outputted in the $logger->info function?$connection
variable.Won't both of this information be valuable to debugging?
How about changing the $logger->info to:
$this->logger->info('Executing command "' . $command . '"' . " [client:{$connection}] [duration:" . round($duration, 2) . "ms]");
For a more verbose output as below:
snc_redis: Executing command "GET foo" [client:cache] [duration:0.32ms]
If this looks good, I can submit a pull request for the same.
Can you add compatibility with phpredis (redis native php extension - https://github.com/nicolasff/phpredis)?
I used filth/redis-bundle, which connected to this bundle, but in a composer a link look like as "2.1.*". Last month it's work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.