webdcg/redis

Redis client for PHP using the PhpRedis C Extension

0.14.0 2020-02-26 04:08 UTC

This package is auto-updated.

Last update: 2024-10-28 14:07:51 UTC


README

StyleCI Latest Version on Packagist Build Status Quality Score Total Downloads

OOP Redis client for PHP using the PhpRedis C Extension

Table of contents

  1. Installation
  2. Classes and methods

Installation

You can install the package via composer:

composer require webdcg/redis

Classes and methods

Usage

$redis = new Webdcg\Redis\Redis;

Bits

// Count set bits in a string
$redis->bitCount('key');
$redis->bitField('key');
$redis->bitPos('key');
$redis->bitOp('key');
$redis->getBit('key');
$redis->setBit('key');

Connection

$redis->connect('127.0.0.1', 6379);
$redis->open('127.0.0.1', 6379);
$redis->pconnect('127.0.0.1', 6379);
$redis->popen('127.0.0.1', 6379);
$redis->auth('secret');
$redis->select(1);
$redis->swapdb(0, 1);
$redis->close();
$redis->setOption(\Redis::OPT_PREFIX, 'redis:');
$redis->getOption(\Redis::OPT_PREFIX)
$redis->ping('pong');
$redis->echo('redis');

Geocoding

$options = ['WITHDIST'];
$redis->geoAdd('Geocoding', -122.431, 37.773, 'San Francisco');
$redis->geoAdd('Geocoding', -73.935242, 40.730610, 'New York');
$redis->geoHash('Geocoding', 'San Francisco');
$redis->geoPos('Geocoding', 'San Francisco');
$redis->geoDist('Geocoding', 'San Francisco', 'New York');
$redis->geoRadius("Geocoding", -157.858, 21.306, 300, 'mi', $options);
$redis->geoRadiusByMember("Geocoding", 'San Francisco', 300, 'mi', $options);

Hashes

$redis->del('key');
$redis->delete('key');
$redis->unlink('key');

HyperLogLogs

$redis->pfAdd('HyperLogLog', ['a', 'b', 'c']);
$redis->pfCount('HyperLogLog'); // 3
$redis->pfAdd('HyperLogLog2', ['b', 'd']);
$redis->pfMerge('HyperLogLogMerged', ['HyperLogLog', 'HyperLogLog2']);
$redis->pfCount('HyperLogLogMerged'); // 4 => a, b, c, d

Introspection

$redis->del('key');
$redis->delete('key');
$redis->unlink('key');

Keys

$redis->del('key');
$redis->delete('key');
$redis->unlink('key');

Lists

$redis->del('key');
$redis->delete('key');
$redis->unlink('key');

Pub/sub

$redis->del('key');
$redis->delete('key');
$redis->unlink('key');

Scripting

$redis->del('key');
$redis->delete('key');
$redis->unlink('key');

Sets

$redis->del('key');
$redis->delete('key');
$redis->unlink('key');

Sorted Sets

$redis->del('key');
$redis->delete('key');
$redis->unlink('key');

Streams

$redis->del('key');
$redis->delete('key');
$redis->unlink('key');

Strings

// 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:'.time(), 'value', ['nx', 'ex' => 10]);
// Will set a key, if it does exist, with a ttl of 1000 miliseconds
$redis->set('key', 'value', ['xx', 'px' => 1000]);
$redis->setEx('key', 10, 'value');

Transactions

$redis->del('key');
$redis->delete('key');
$redis->unlink('key');

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email rluna@webdcg.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

PHP Package Boilerplate

This package was generated using the PHP Package Boilerplate.