andrewdyer/predis-adaptor

A helper for caching slow operations using Redis.

1.2.0 2023-01-26 11:50 UTC

This package is auto-updated.

Last update: 2024-03-27 00:47:11 UTC


README

A helper for caching slow operations using Redis.

Total Downloads Latest Stable Version License

License

Licensed under MIT. Totally free for private or commercial projects.

Installation

composer require andrewdyer/predis-adaptor

Usage

<?php

$cache = new Anddye\PredisAdaptor\Cache([
    'host'      => '',
    'password'  => '',
    'port'      => '',
    'scheme'    => '',
]);

Supported Options

Option Type Default Description
host string 127.0.0.1 IP or hostname of the target server.
password string not set Accepts a value used to authenticate with a Redis server protected by password with the AUTH command.
port string 6379 TCP/IP port of the target server.
scheme string tcp Specifies the protocol used to communicate with an instance of Redis.

Methods

Method Description
$cache->client()
$cache->delete(string $key)
$cache->exists(string $key)
$cache->get(string $key)
$cache->put(string $key, $value, int $minutes = 10)
$cache->remember(string $key, int $minutes, callable $callback)

Delete

$cache->delete('my_key');
unset($cache->my_key);
unset($cache['my_key'])

Exists

$bool = $cache->exists('my_key');
$bool = isset($cache->my_key);

Get

$value = $cache->get('my_key');
$value = $cache->my_key;

Put

$cache->put('my_key', 'my_value');
$cache->my_key = 'my_value';

Remember

$value = $cache->remember('my_key', 10, function () {
    return 'my_value';
});

Useful Links