An open API service indexing awesome lists of open source software.

https://github.com/initphp/redis

PHP Redis Management Library
https://github.com/initphp/redis

Last synced: about 2 months ago
JSON representation

PHP Redis Management Library

Awesome Lists containing this project

README

          

## InitPHP Redis Management

> ## ⚠️ DEPRECATED — No Longer Maintained
>
> This package was a thin convenience wrapper around the PHP `ext-redis` extension, adding prefix handling and automatic `serialize()` of values. As part of the InitPHP package consolidation, **it has been retired:**
>
> - **PHP 8+ ships `ext-redis` with fully typed methods**, so a wrapper adds little over the native API.
> - The automatic `serialize()` adds non-trivial CPU + network overhead and is rarely what callers want today.
> - No package in the InitPHP ecosystem currently depends on this one. (`initphp/cache` and `initphp/sessions` both talk to `\Redis` directly.)
>
> This repository is kept read-only for historical reference. **No further updates will be released.**
>
> ### What to use instead
>
> Pick the closest match to what you were doing:
>
> **Caching key/value data** — use [`initphp/cache`](https://github.com/InitPHP/Cache) with its bundled Redis handler:
>
> ```php
> use InitPHP\Cache\Handler\Redis as RedisCache;
>
> $cache = new RedisCache([
> 'host' => '127.0.0.1',
> 'port' => 6379,
> ]);
> $cache->set('name', 'muhammet');
> ```
>
> **Storing session data** — use [`initphp/sessions`](https://github.com/InitPHP/Sessions) with its `RedisAdapter`. See the Sessions README for the Redis usage example.
>
> **Anything else** (Pub/Sub, Lua scripts, Cluster, pipelining, low-level Redis commands) — call `\Redis` directly. It is the canonical, fully-typed entry point and supports the full Redis feature surface:
>
> ```php
> $redis = new \Redis();
> $redis->connect('127.0.0.1', 6379);
> $redis->set('name', 'muhammet');
> $value = $redis->get('name');
> ```
>
> Composer will surface this package as `abandoned` on `composer require`, `composer update`, and `composer outdated`.

---

This library was born to facilitate and customize the use of getter and setter of PHP and Redis.

## Requirements

- PHP 7.4 or later
- PHP Redis Extension

## Installation

```
composer require initphp/redis
```

## Usage

```php
require_once "vendor/autoload.php";
use \InitPHP\Redis\Redis;

// Provide your connection information;
$redis = new Redis([
'prefix' => 'i_',
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'timeout' => 0,
'database' => 0,
]);

// Use Setter and Getter;
$redis->set('name', 'muhammet');
if($redis->has('name')){
echo $redis->get('name'); // "muhammet"
}

/**
* or tell the get method what it will
* do if it can't find it,
* or a default value it will return;
*/
echo $redis->get('username', 'Undefined'); // "Undefined"

echo $redis->get('surname', function () use ($redis) {
$value = 'ŞAFAK';
$redis->set('surname', $value);
return $value;
}); // "ŞAFAK"
```

## Credits

- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) <>

## License

Copyright © 2022 [MIT License](./LICENSE)