initphp/redis

InitPHP Redis 管理

1.0 2022-11-05 06:20 UTC

This package is auto-updated.

Last update: 2024-09-05 10:14:52 UTC


README

这个库是为了方便和定制PHP和Redis的getter和setter的使用而诞生的。

要求

  • PHP 7.4或更高版本
  • PHP Redis 扩展

安装

composer require initphp/redis

使用

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"

致谢

许可

版权 © 2022 MIT许可