@@ -41,26 +41,25 @@ class RedisSessionHandler extends AbstractSessionHandler
4141
4242 /**
4343 * List of available options:
44- * * prefix: The prefix to use for the Redis keys in order to avoid collision
45- * * expiretime: The time to live in seconds.
44+ * * prefix: The prefix to use for the keys in order to avoid collision
45+ * * expiretime: The time to live in seconds. Defaults to 1 day.
4646 *
47- * @param \Redis $redis A \Redis instance
48- * @param array $options An associative array of Redis options
47+ * @param \Redis $redis A \Redis instance
48+ * @param null| array $options An associative array of options
4949 *
5050 * @throws \InvalidArgumentException When unsupported options are passed
5151 */
52- public function __construct (\Redis $ redis , array $ options = null )
52+ public function __construct (\Redis $ redis , ? array $ options = null )
5353 {
5454 $ this ->redis = $ redis ;
55+ $ options = (array ) $ options ;
5556
5657 if ($ diff = array_diff (array_keys ($ options ), array ('prefix ' , 'expiretime ' ))) {
57- throw new \InvalidArgumentException (sprintf (
58- 'The following options are not supported "%s" ' , implode (', ' , $ diff )
59- ));
58+ throw new \InvalidArgumentException (sprintf ('The following options are not supported "%s" ' , implode (', ' , $ diff )));
6059 }
6160
6261 $ this ->ttl = isset ($ options ['expiretime ' ]) ? (int ) $ options ['expiretime ' ] : 86400 ;
63- $ this ->prefix = isset ( $ options ['prefix ' ]) ? $ options [ ' prefix ' ] : ' sf2s ' ;
62+ $ this ->prefix = $ options ['prefix ' ] ?? ' sf_s ' ;
6463 }
6564
6665 /**
@@ -76,18 +75,17 @@ protected function doRead($sessionId)
7675 */
7776 protected function doWrite ($ sessionId , $ data )
7877 {
79- return $ this ->redis ->set ($ this ->prefix .$ sessionId , $ data , $ this ->ttl );
78+ return $ this ->redis ->setEx ($ this ->prefix .$ sessionId , $ this ->ttl , $ data );
8079 }
8180
8281 /**
8382 * {@inheritdoc}
8483 */
8584 protected function doDestroy ($ sessionId )
8685 {
87- // number of deleted items
88- $ count = $ this ->redis ->del ($ this ->prefix .$ sessionId );
86+ $ this ->redis ->delete ($ this ->prefix .$ sessionId );
8987
90- return 1 === $ count ;
88+ return true ;
9189 }
9290
9391 /**
0 commit comments