dtkahl/php-simple-redis-cache

1.0.1 2017-03-19 10:38 UTC

This package is auto-updated.

Last update: 2024-11-29 05:03:30 UTC


README

Latest Stable Version License Build Status

PHP simple redis cache

This is a simple cache class for PHP using redis trough predis/predis.

Dependencies

  • PHP >= 5.6.0
  • a redis server

Installation

Install with Composer:

composer require dtkahl/php-simple-redis-cache

Usage

Refer namespace:

use Dtkahl\SimpleRedisCache;

Create new Cache instance:

$cache = new Cache([
    "scheme" => "tcp",
    "host => "127.0.0.1",
    "port" => 6379
);

Methods

put($key, $value, $time = null)

Put item to cache. (time in seconds)

$cache->put('foo', 'bar', 60)

has($key)

Determinate if key exists in cache.

$cache->has('foo')

get($key, $default = null)

Return Item from cache or $default.

$cache->get('foo', 'default')

forget($key)

Remove item from cache.

$cache->forget('foo')

forever($key, $value)

Store item in cache forever.

$cache->forever('foo', 'bar')

remember($key, $callback, $time = null)

Return cache item if exists otherwise call $callback, cache the returned value and return it.

$cache->put('foo')