Leaf PHP

Redis
in package

Leaf + Redis [BETA] ---------- Redis made crazy simple

Tags
since
2.5.1
author

Michael Darko mickdd22@gmail.com

version
4.0.0-beta

Table of Contents

Properties

$config  : array<string|int, mixed>
Leaf Redis config
$redis  : Adapter

Methods

__construct()  : mixed
close()  : void
Close the redis connection
commands()  : array<string|int, mixed>
Get all leaf redis console commands
connect()  : Redis
Initialize redis and connect to redis instance
connection()  : Adapter
Get the redis connection
delete()  : bool
Delete a key from redis
errors()  : array<string|int, mixed>
Return all saved errors
exists()  : bool
Check if a key exists in redis
flush()  : bool
Flush all keys in redis
get()  : string|mixed|false
Get a redis value
keys()  : array<string|int, mixed>
Get all keys in redis
ping()  : bool|string
Ping redis server.
set()  : bool
Set a redis value
parseSaveOptions()  : mixed
setSessionHandler()  : mixed

Properties

$config

Leaf Redis config

protected array<string|int, mixed> $config = ['port' => 6379, 'scheme' => 'tcp', 'password' => null, 'host' => '127.0.0.1', 'session' => false, 'session.savePath' => null, 'session.saveOptions' => [], 'connection.timeout' => 0.0, 'connection.reserved' => null, 'connection.retryInterval' => 0, 'connection.readTimeout' => 0.0]

Methods

__construct()

public __construct() : mixed

close()

Close the redis connection

public close() : void

commands()

Get all leaf redis console commands

public commands() : array<string|int, mixed>
Return values
array<string|int, mixed>

connect()

Initialize redis and connect to redis instance

public connect([array<string|int, mixed> $config = [] ]) : Redis
Parameters
$config : array<string|int, mixed> = []

Configuration for the redis instance.

Return values
Redis

delete()

Delete a key from redis

public delete(string|array<string|int, mixed> $key) : bool
Parameters
$key : string|array<string|int, mixed>

The key to delete

Tags
link
https://redis.io/commands/del
Return values
bool

errors()

Return all saved errors

public errors() : array<string|int, mixed>
Return values
array<string|int, mixed>

get()

Get a redis value

public get(string|array<string|int, mixed> $key) : string|mixed|false
Parameters
$key : string|array<string|int, mixed>

The value(s) to get

Tags
link
https://redis.io/commands/get
Return values
string|mixed|false

If key didn't exist, FALSE is returned. Otherwise, the value related to this key is returned

ping()

Ping redis server.

public ping([string|null $message = null ]) : bool|string
Parameters
$message : string|null = null

— [optional]

Tags
throws
Exception
link
https://redis.io/commands/ping
Return values
bool|string

TRUE if the command is successful or returns message Throws a RedisException object on connectivity error, as described above

set()

Set a redis value

public set(string|array<string|int, mixed> $key[, string|mixed $value = "" ][, int|array<string|int, mixed> $timeout = 0 ]) : bool
Parameters
$key : string|array<string|int, mixed>

The value(s) to set

$value : string|mixed = ""

— string if not used serializer

$timeout : int|array<string|int, mixed> = 0

[optional] Calling setex() is preferred if you want a timeout.

Since 2.6.12 it also supports different flags inside an array. Example ['NX', 'EX' => 60]

  • EX seconds -- Set the specified expire time, in seconds.
  • PX milliseconds -- Set the specified expire time, in milliseconds.
  • NX -- Only set the key if it does not already exist.
  • XX -- Only set the key if it already exist. // Simple key -> value set $redis->set('key', 'value'); // Will redirect, and actually make an SETEX call $redis->set('key','value', 10); // Will set the key, if it doesn't exist, with a ttl of 10 seconds $redis->set('key', 'value', ['nx', 'ex' => 10]); // Will set a key, if it does exist, with a ttl of 1000 milliseconds $redis->set('key', 'value', ['xx', 'px' => 1000]);
Tags
link
https://redis.io/commands/set
since

If you're using Redis >= 2.6.12, you can pass extended options as explained in example

Return values
bool

— TRUE if the command is successful

parseSaveOptions()

protected parseSaveOptions() : mixed

setSessionHandler()

protected setSessionHandler() : mixed

        
On this page

Search results