PHP Класс yii\redis\Session

Redis Session requires redis version 2.6.12 or higher to work properly. It needs to be configured with a redis Connection that is also configured as an application component. By default it will use the redis application component. To use redis Session as the session application component, configure the application as follows, ~~~ [ 'components' => [ 'session' => [ 'class' => 'yii\redis\Session', 'redis' => [ 'hostname' => 'localhost', 'port' => 6379, 'database' => 0, ] ], ], ] ~~~ Or if you have configured the redis Connection as an application component, the following is sufficient: ~~~ [ 'components' => [ 'session' => [ 'class' => 'yii\redis\Session', 'redis' => 'redis' // id of the connection application component ], ], ] ~~~
С версии: 2.0
Автор: Carsten Brandt ([email protected])
Наследование: extends yii\web\Session
Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
$keyPrefix a string prefixed to every cache key so that it is unique. If not set, it will use a prefix generated from [[Application::id]]. You may set this property to be an empty string if you don't want to use key prefix. It is recommended that you explicitly set this property to some static value if the cached data needs to be shared among multiple applications.
$redis the Redis Connection object or the application component ID of the Redis Connection. This can also be an array that is used to create a redis Connection instance in case you do not want do configure redis connection as an application component. After the Session object is created, if you want to change this property, you should only assign it with a Redis Connection object.

Открытые методы

Метод Описание
destroySession ( string $id ) : boolean Session destroy handler.
getUseCustomStorage ( ) : boolean Returns a value indicating whether to use custom session storage.
init ( ) Initializes the redis Session component.
readSession ( string $id ) : string Session read handler.
writeSession ( string $id, string $data ) : boolean Session write handler.

Защищенные методы

Метод Описание
calculateKey ( string $id ) : string Generates a unique key used for storing session data in cache.

Описание методов

calculateKey() защищенный Метод

Generates a unique key used for storing session data in cache.
protected calculateKey ( string $id ) : string
$id string session variable name
Результат string a safe cache key associated with the session variable name

destroySession() публичный Метод

Do not call this method directly.
public destroySession ( string $id ) : boolean
$id string session ID
Результат boolean whether session is destroyed successfully

getUseCustomStorage() публичный Метод

This method overrides the parent implementation and always returns true.
public getUseCustomStorage ( ) : boolean
Результат boolean whether to use custom storage.

init() публичный Метод

This method will initialize the [[redis]] property to make sure it refers to a valid redis connection.
public init ( )

readSession() публичный Метод

Do not call this method directly.
public readSession ( string $id ) : string
$id string session ID
Результат string the session data

writeSession() публичный Метод

Do not call this method directly.
public writeSession ( string $id, string $data ) : boolean
$id string session ID
$data string session data
Результат boolean whether session write is successful

Описание свойств

$keyPrefix публичное свойство

a string prefixed to every cache key so that it is unique. If not set, it will use a prefix generated from [[Application::id]]. You may set this property to be an empty string if you don't want to use key prefix. It is recommended that you explicitly set this property to some static value if the cached data needs to be shared among multiple applications.
public $keyPrefix

$redis публичное свойство

the Redis Connection object or the application component ID of the Redis Connection. This can also be an array that is used to create a redis Connection instance in case you do not want do configure redis connection as an application component. After the Session object is created, if you want to change this property, you should only assign it with a Redis Connection object.
public $redis