承接 ftuzlu/redis-cache-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ftuzlu/redis-cache-php

最新稳定版本:1.0.0

Composer 安装命令:

composer require ftuzlu/redis-cache-php

包简介

Generic Redis For PHP

README 文档

README

Install Dependencies:

composer require ftuzlu/redis-cache

Establish Redis Connection:

  • First step is connect to Redis with Connect class
<?php
require_once('vendor/autoload.php');

use Fatihtuzlu\RedisCachePhp\Connection;
use Fatihtuzlu\RedisCachePhp\RedisCache;
use Predis\Client;

$connection = new Connection('tcp', '127.0.0.1', '6379');

$client = new Client();
$redisCache = new RedisCache($connection, $client);

$redisCache->set('example_key', 'Hello, Redis Cache!');

$val = $redisCache->getAllCachedData();
var_dump($val);

$value = $redisCache->get('example_key');
echo $value; // Output: Hello, Redis Cache!

$redisCache->delete('example_key'); //delete redis

Cache Mecanism

  • If you want you can use cache mecanism

Cache Create Usage

  • Create function is create cache
<?php

require_once('vendor/autoload.php');

$cacheInstance = new Symfony\Component\Cache\Simple\FilesystemCache();

$myCache = new Fatihtuzlu\CacheMecanism\Cache($cacheInstance);

$result = $myCache->create('new_key', 'New value', 3600);

Remember Cache and Retrieve Data:

<?php

require_once('vendor/autoload.php');

$cacheInstance = new Symfony\Component\Cache\Simple\FilesystemCache();

$myCache = new Fatihtuzlu\CacheMecanism\Cache($cacheInstance);

$result = $myCache->remember('example_key', function () {
    echo 'Calculating result...' . PHP_EOL;
    return 42;
}, 60);

echo 'Result: ' . $result . PHP_EOL;

Remember Cache Forever and Retrieve Data:

<?php

require_once('vendor/autoload.php');

$cacheInstance = new Symfony\Component\Cache\Simple\FilesystemCache();

$myCache = new Fatihtuzlu\CacheMecanism\Cache($cacheInstance);

$result = $myCache->rememberForever('example_key', function () {
    echo 'Calculating result...' . PHP_EOL;
    return 42;
});

echo 'Result: ' . $result . PHP_EOL;

Forget Cache Data:

<?php

require_once('vendor/autoload.php');

$cacheInstance = new Symfony\Component\Cache\Simple\FilesystemCache();

$myCache = new Fatihtuzlu\CacheMecanism\Cache($cacheInstance);

$result = $myCache->forget('new_key');

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-09