Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 39ea33e

Browse files
committed
Merge branch 'master' of git://github.com/owlient/phpredis
2 parents 4dd9bf6 + 0267ad8 commit 39ea33e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

README.markdown

+7-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ Session handler (new)
4343
phpredis can be used to store PHP sessions. To do this, configure `session.save_handler` and `session.save_path` in your php.ini to tell phpredis where to store the sessions:
4444
<pre>
4545
session.save_handler = redis
46-
session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2, tcp://host3:6379?weight=2"
46+
session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2"
4747
</pre>
4848

49-
`session.save_path` can have a simple `host:port` format too, but you need to provide the `tcp://` scheme if you want to use the weight parameter.
49+
`session.save_path` can have a simple `host:port` format too, but you need to provide the `tcp://` scheme if you want to use the parameters. The following parameters are available:
50+
51+
* weight (integer): the weight of a host is used in comparison with the others in order to customize the session distribution on several hosts. If host A has twice the weight of host B, it will get twice the amount of sessions. In the example, *host1* stores 20% of all the sessions (1/(1+2+2)) while *host2* and *host3* each store 40% (2/1+2+2). The target host is determined once and for all at the start of the session, and doesn't change. The default weight is 1.
52+
* timeout (float): the connection timeout to a redis host, expressed in seconds. If the host is unreachable in that amount of time, the session storage will be unavailable for the client. The default timeout is very high (86400 seconds).
53+
54+
Sessions have a lifetime expressed in seconds and stored in the INI variable "session.gc_maxlifetime". You can change it with [`ini_set()`](http://php.net/ini_set).
5055

5156
Error handling
5257
==============

redis_session.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ redis_pool_get_sock(redis_pool *pool, const char *key TSRMLS_DC) {
106106
return rpm->redis_sock;
107107
}
108108
i += rpm->weight;
109+
rpm = rpm->next;
109110
}
110111

111112
return NULL;
@@ -133,7 +134,8 @@ PS_OPEN_FUNC(redis)
133134
j++;
134135

135136
if (i < j) {
136-
int weight = 1, timeout = 86400;
137+
int weight = 1;
138+
double timeout = 86400.0;
137139

138140
/* unix: isn't supported yet. */
139141
if (!strncmp(save_path+i, "unix:", sizeof("unix:")-1)) {
@@ -173,8 +175,7 @@ PS_OPEN_FUNC(redis)
173175
}
174176

175177
if (zend_hash_find(Z_ARRVAL_P(params), "timeout", sizeof("timeout"), (void **) &param) != FAILURE) {
176-
convert_to_long_ex(param);
177-
timeout = Z_LVAL_PP(param);
178+
timeout = atof(Z_STRVAL_PP(param));
178179
}
179180

180181
/* // not supported yet
@@ -287,7 +288,7 @@ PS_WRITE_FUNC(redis)
287288

288289
/* send SET command */
289290
session = redis_session_key(key, strlen(key), &session_len);
290-
cmd_len = redis_cmd_format_static(&cmd, "SET", "ss", session, session_len, val, vallen);
291+
cmd_len = redis_cmd_format_static(&cmd, "SETEX", "sds", session, session_len, INI_INT("session.gc_maxlifetime"), val, vallen);
291292
efree(session);
292293
if(redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) {
293294
efree(cmd);

0 commit comments

Comments
 (0)