mp3000mp/redis-client

Simple class easy to use that wraps Redis extension without dependencies.

0.1 2020-11-01 12:09 UTC

This package is auto-updated.

Last update: 2024-03-29 04:25:57 UTC


README

Simple class easy to use that wraps Redis extension without dependencies.

Packagist Version Build Status Coverage Status License

Table of Contents

Installation

composer require mp3000mp/redis-client

Usage

// This will try to connect and throw a RedisClientException if connection failed
$client = new RedisClient($host, $port, $auth);

// simple get set system
$client->set('key', 'value');
$val = $client->get('key');

// this value will be converted into json text into redis
$client->set('key_array', ['test' => 'test']);
// returns '{"test":"test"}'
$client->get('key_array');
// returns ['test' => 'test']
$client->get('key_array', true);

// this key will live 120 seconds
$client->set('key', 'test', 120); 
$client->delete('key');

// close connection
$client->close();

Use with Symfony

Add this to services.yml

    Mp3000mp\RedisClient\RedisClient:
        arguments: ['%env(REDIS_HOST)%', '%env(REDIS_PORT)%', '%env(REDIS_AUTH)%']