Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add support for serializer setting in redis.ini. #326

Open
wants to merge 1 commit into from

4 participants

@mruoss

Hi there

I think it makes sense to configure the serializer system wide in the redis.ini file. This can still be changed calling $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_XYZ); in the code.

I decided to keep the INI-setting readable and defined new constants containing the possible string values for this setting.

Regards,
Michael

@nicolasff
Owner

Looks great, thanks!

@jlgeering

Hi Nicolas,

could you please pull, if you're happy with the changes ?

cheers

@michael-grunder

Hey there,

I will be pushing a couple of things to phpredis over the weekend. I will give this a quick test and then merge it in for you guys :)

Cheers,
Mike

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 2, 2013
  1. @mruoss
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 2 deletions.
  1. +5 −1 README.markdown
  2. +4 −0 common.h
  3. +15 −1 library.c
  4. +3 −0  redis.c
View
6 README.markdown
@@ -44,7 +44,11 @@ make && make install
~~~
If you would like phpredis to serialize your data using the igbinary library, run configure with `--enable-redis-igbinary`.
-`make install` copies `redis.so` to an appropriate location, but you still need to enable the module in the PHP config file. To do so, either edit your php.ini or add a redis.ini file in `/etc/php5/conf.d` with the following contents: `extension=redis.so`.
+`make install` copies `redis.so` to an appropriate location, but you still need to enable the module in the PHP config file. To do so, either edit your php.ini or add a redis.ini file in `/etc/php5/conf.d` with the following contents:
+
+ extension=redis.so
+ ; optional: Set to igbinary | php | none
+ redis.serializer=igbinary
You can generate a debian package for PHP5, accessible from Apache 2 by running `./mkdeb-apache2.sh` or with `dpkg-buildpackage` or `svn-buildpackage`.
View
4 common.h
@@ -42,6 +42,10 @@ typedef enum _REDIS_REPLY_TYPE {
#define REDIS_SERIALIZER_PHP 1
#define REDIS_SERIALIZER_IGBINARY 2
+#define INI_REDIS_SERIALIZER_NONE "none"
+#define INI_REDIS_SERIALIZER_PHP "php"
+#define INI_REDIS_SERIALIZER_IGBINARY "igbinary"
+
#define IF_MULTI() if(redis_sock->mode == MULTI)
#define IF_MULTI_OR_ATOMIC() if(redis_sock->mode == MULTI || redis_sock->mode == ATOMIC)\
View
16 library.c
@@ -843,6 +843,7 @@ PHPAPI RedisSock* redis_sock_create(char *host, int host_len, unsigned short por
double timeout, int persistent, char *persistent_id)
{
RedisSock *redis_sock;
+ char *ini_serializer;
redis_sock = ecalloc(1, sizeof(RedisSock));
redis_sock->host = estrndup(host, host_len);
@@ -868,7 +869,20 @@ PHPAPI RedisSock* redis_sock_create(char *host, int host_len, unsigned short por
redis_sock->timeout = timeout;
redis_sock->read_timeout = timeout;
- redis_sock->serializer = REDIS_SERIALIZER_NONE;
+ ini_serializer = INI_STR("redis.serializer");
+ if (!strcmp(ini_serializer, INI_REDIS_SERIALIZER_PHP)) {
+ redis_sock->serializer = REDIS_SERIALIZER_PHP;
+ } else if (!strcmp(ini_serializer, INI_REDIS_SERIALIZER_IGBINARY)) {
+#ifdef HAVE_REDIS_IGBINARY
+ redis_sock->serializer = REDIS_SERIALIZER_IGBINARY;
+#else
+ zend_error(E_NOTICE, "phpredis was compiled without support for igbinary. Your INI-setting `redis.serializer=igbinary` has no effect. Falling back to no serialization.");
+ redis_sock->serializer = REDIS_SERIALIZER_NONE;
+#endif
+ } else {
+ redis_sock->serializer = REDIS_SERIALIZER_NONE;
+ }
+
redis_sock->mode = ATOMIC;
redis_sock->head = NULL;
redis_sock->current = NULL;
View
3  redis.c
@@ -59,6 +59,9 @@ zend_class_entry *spl_ce_RuntimeException = NULL;
extern zend_function_entry redis_array_functions[];
PHP_INI_BEGIN()
+ /* redis serialization */
+ PHP_INI_ENTRY("redis.serializer", INI_REDIS_SERIALIZER_NONE, PHP_INI_ALL, NULL)
+
/* redis arrays */
PHP_INI_ENTRY("redis.arrays.names", "", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("redis.arrays.hosts", "", PHP_INI_ALL, NULL)
Something went wrong with that request. Please try again.