https://github.com/dantodev/php-simple-redis-cache
A simple redis cache class using Predis
https://github.com/dantodev/php-simple-redis-cache
cache php redis redis-cache
Last synced: 10 months ago
JSON representation
A simple redis cache class using Predis
- Host: GitHub
- URL: https://github.com/dantodev/php-simple-redis-cache
- Owner: dantodev
- License: mit
- Created: 2017-03-19T09:27:19.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-02-14T11:37:12.000Z (over 7 years ago)
- Last Synced: 2025-08-15T14:59:24.381Z (10 months ago)
- Topics: cache, php, redis, redis-cache
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://packagist.org/packages/dtkahl/php-simple-redis-cache)
[](https://packagist.org/packages/dtkahl/php-simple-redis-cache)
[](https://travis-ci.org/dtkahl/php-simple-redis-cache)
# 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](http://getcomposer.org):
```
composer require dtkahl/php-simple-redis-cache
```
### Usage
Refer namespace:
```
use Dtkahl\SimpleRedisCache;
```
Create new Cache instance:
```php
$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)
```php
$cache->put('foo', 'bar', 60)
```
#### `has($key)`
Determinate if key exists in cache.
```php
$cache->has('foo')
```
#### `get($key, $default = null)`
Return Item from cache or `$default`.
```php
$cache->get('foo', 'default')
```
#### `forget($key)`
Remove item from cache.
```php
$cache->forget('foo')
```
#### `forever($key, $value)`
Store item in cache forever.
```php
$cache->forever('foo', 'bar')
```
#### `remember($key, $callback, $time = null)`
Return cache item if exists otherwise call `$callback`, cache the returned value and return it.
```php
$cache->put('foo')
```