k911/swoole-bundle

View on GitHub
src/Server/Session/StorageInterface.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
<?php

declare(strict_types=1);

namespace K911\Swoole\Server\Session;

interface StorageInterface
{
    /**
     * Add or update session storage storage by key.
     *
     * @param mixed $data
     * @param int   $ttl  lifetime in seconds
     */
    public function set(string $key, $data, int $ttl): void;

    /**
     * Delete session storage by key.
     */
    public function delete(string $key): void;

    /**
     * Invalidate all expired session storage.
     */
    public function garbageCollect(): void;

    /**
     * Get session storage data by key.
     *
     * @param null|callable $expired What to do when key has expired (for example: delete data)
     *                               Signature: function(string $key, $data): void {}
     *
     * @return null|mixed data Should return the same type as provided in set(), null when data is not available or expired
     */
    public function get(string $key, ?callable $expired = null);
}