Yii Caching Library - Redis Handler

Overview

Yii Caching Library - Redis Handler


Latest Stable Version Total Downloads Build status Scrutinizer Code Quality Code Coverage Mutation testing badge static analysis type-coverage

This package provides the Redis handler and implements PSR-16 cache.

Requirements

  • PHP 7.4 or higher.

Installation

The package could be installed with composer:

composer require yiisoft/cache-redis --prefer-dist

General usage

For more information about the client instance and connection configuration, see the documentation of the predis/predis package.

/**
 * @var \Predis\ClientInterface $client Predis client instance to use.
 */
$cache = new \Yiisoft\Cache\Redis\RedisCache($client);

The package does not contain any additional functionality for interacting with the cache, except those defined in the PSR-16 interface.

$parameters = ['user_id' => 42];
$key = 'demo';

// try retrieving $data from cache
$data = $cache->get($key);

if ($data === null) {
    // $data is not found in cache, calculate it from scratch
    $data = calculateData($parameters);
    
    // store $data in cache for an hour so that it can be retrieved next time
    $cache->set($key, $data, 3600);
}

// $data is available here

In order to delete value you can use:

$cache->delete($key);
// Or all cache
$cache->clear();

To work with values in a more efficient manner, batch operations should be used:

  • getMultiple()
  • setMultiple()
  • deleteMultiple()

This package can be used as a cache handler for the Yii Caching Library.

Testing

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

Mutation testing

The package tests are checked with Infection mutation framework with Infection Static Analysis Plugin. To run it:

./vendor/bin/roave-infection-static-analysis-plugin

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

./vendor/bin/psalm

License

The Yii Caching Library - Redis Handler is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

Comments
  • Why such check of keys?

    Why such check of keys?

    What steps will reproduce the problem?

    Migrate from Yii2

    What is the expected result?

    Don't see the different in behavior

    What do you get instead?

    I get an exception

    Additional info

    | Q | A | ---------------- | --- | Version | 1.0.0 | PHP version | 8.0.21 | Operating system | Alpine

    I have a method that automatically generates a key based on the name of the method and the passed parameters. And it worked well enough. There is an interesting check in the new version, the meaning of which I do not understand

    if (!is_string($key) || $key === '' || strpbrk($key, '{}()/\@:')) {
        throw new InvalidArgumentException('Invalid key value.');
    }
    

    Can you explain why such validation was introduced for the key?

    This is basically '{}()/\@:'

    opened by s1lver 1
  • Update psr/simple-cache requirement from ^1.0.1 to ^3.0.0

    Update psr/simple-cache requirement from ^1.0.1 to ^3.0.0

    Updates the requirements on psr/simple-cache to permit the latest version.

    Release notes

    Sourced from psr/simple-cache's releases.

    3.0.0

    • Adds return types

    See the meta doc, section Errata for more details: https://www.php-fig.org/psr/psr-16/meta/

    Commits
    • 764e0b3 Merge pull request #24 from navarr/return-types
    • 8707bf3 Merge pull request #25 from php-fig/param-types
    • dd145de Make CacheException extend Throwable
    • 66e27ef Merge pull request #21 from J0WI/patch-1
    • 19a4d7c Add return types
    • 0f32180 Add parameter types
    • 8ffc7a5 Update iterable doc types to identify values and in some cases keys
    • 138d674 Update url to HTTPS
    • 5a7b96b Merge pull request #20 from polishExperiment/patch-1
    • 0ca494d Update CacheInterface.php
    • See full diff in compare view

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies php 
    opened by dependabot[bot] 1
  • Separate chain calls

    Separate chain calls

    | Q | A | ------------- | --- | Readability fix | according to https://github.com/yiisoft/docs/issues/155, chain calls must be put on separate lines.

    status:code review 
    opened by sankaest 0
  • (#7) Added configure CI with Redis single and cluster instance

    (#7) Added configure CI with Redis single and cluster instance

    | Q | A | ------------- | --- | Is bugfix? | ✔️ | New feature? | ❌ | Breaks BC? | ❌ | Fixed issues | #7

    • Changed CI to run single and clustered Redis
    • Added identical tests with a connection to the Redis cluster
    • Updated predis to 2.0 (#4)
    type:test 
    opened by s1lver 3
  • Cannot use 'FLUSHDB' with redis-cluster

    Cannot use 'FLUSHDB' with redis-cluster

    What steps will reproduce the problem?

    1. Set up Redis cluster
    2. Call method $this->instance->clear()
    public function clear(): bool
    {
        return $this->client->flushdb() !== null;
    }
    

    What is the expected result?

    Completed cleaning

    What do you get instead?

    I get an exception

    Additional info

    | Q | A | ---------------- | --- | Version | 1.0.0 | PHP version | 8.0.21 | Operating system | Alpine | Redis | 6.2.6 - 7.0.4

    type:bug 
    opened by s1lver 7
  • Update predis/predis requirement from ^1.1 to ^2.0

    Update predis/predis requirement from ^1.1 to ^2.0

    Updates the requirements on predis/predis to permit the latest version.

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies php 
    opened by dependabot[bot] 0
Owner
Yii Software
Yii Framework and packages
Yii Software
Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output

laminas-cache Laminas\Cache provides a general cache system for PHP. The Laminas\Cache component is able to cache different patterns (class, object, o

Laminas Project 69 Jan 7, 2023
Stash - A PHP Caching Library

Stash - A PHP Caching Library Stash makes it easy to speed up your code by caching the results of expensive functions or code. Certain actions, like d

Tedious Developments 943 Dec 15, 2022
Symfony Bundle for the Stash Caching Library

TedivmStashBundle The TedivmStashBundle integrates the Stash caching library into Symfony, providing a powerful abstraction for a range of caching eng

Tedious Developments 86 Aug 9, 2022
PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APC(u), SQL and additional capabilities (e.g. transactions, stampede protection) built on top.

Donate/Support: Documentation: https://www.scrapbook.cash - API reference: https://docs.scrapbook.cash Table of contents Installation & usage Adapters

Matthias Mullie 295 Nov 28, 2022
A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache tagging and indexing.

Apix Cache, cache-tagging for PHP Apix Cache is a generic and thin cache wrapper with a PSR-6 interface to various caching backends and emphasising ca

Apix 111 Nov 26, 2022
Query caching for Laravel

Query caching for Laravel

Dwight Watson 1k Dec 30, 2022
Simple Yet Powerful PHP Caching Class

The PHP high-performance object caching system ever. phpFastCache is a high-performance, distributed object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. phpFastCache dropped the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful

Khoa Bui 28 Aug 19, 2022
Caching extension for the Intervention Image Class

Intervention Image Cache extends the Intervention Image Class package to be capable of image caching functionality.

null 616 Dec 30, 2022
Stash makes it easy to speed up your code by caching the results of expensive functions or code

Stash - A PHP Caching Library Stash makes it easy to speed up your code by caching the results of expensive functions or code. Certain actions, like d

Tedious Developments 943 Dec 15, 2022
DataLoaderPhp is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.

DataLoaderPHP is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.

Webedia - Overblog 185 Nov 3, 2022
The next-generation caching layer for PHP

The next-generation caching layer for PHP

CacheWerk 115 Dec 25, 2022
A flexible and feature-complete Redis client for PHP.

Predis A flexible and feature-complete Redis client for PHP 7.2 and newer. ATTENTION: you are on the README file of an unstable branch of Predis speci

Predis 7.3k Jan 3, 2023
A PHP extension for Redis

PhpRedis The phpredis extension provides an API for communicating with the Redis key-value store. It is released under the PHP License, version 3.01.

null 9.6k Jan 6, 2023
More Than Just a Cache: Redis Data Structures

More Than Just a Cache: Redis Data Structures Redis is a popular key-value store, commonly used as a cache or message broker service. However, it can

Andy Snell 2 Oct 16, 2021
A fast, light-weight proxy for memcached and redis

twemproxy (nutcracker) twemproxy (pronounced "two-em-proxy"), aka nutcracker is a fast and lightweight proxy for memcached and redis protocol. It was

Twitter 11.7k Jan 2, 2023
Zend_Cache backend using Redis with full support for tags

This Zend_Cache backend allows you to use a Redis server as a central cache storage. Tags are fully supported without the use of TwoLevels cache so this backend is great for use on a single machine or in a cluster. Works with any Zend Framework project including all versions of Magento!

Colin Mollenhour 387 Jun 9, 2022
Redis Object Cache for WordPress

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, Credis, HHVM, replication and clustering.

Rhubarb Group 295 Dec 28, 2022
Simple artisan command to debug your redis cache. Requires PHP 8.1 & Laravel 9

?? php artisan cache:debug Simple artisan command to debug your redis cache ?? Installation You can install the package via composer: composer require

Juan Pablo Barreto 19 Sep 18, 2022
CLI App and library to manage apc & opcache.

CacheTool - Manage cache in the CLI CacheTool allows you to work with APCu, OPcache, and the file status cache through the CLI. It will connect to a F

Samuel Gordalina 1.4k Jan 3, 2023