• Stars
    star
    494
  • Rank 89,130 (Top 2 %)
  • Language
    C
  • License
    BSD 2-Clause "Sim...
  • Created almost 14 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP extension for Redis based on Hiredis

Phpiredis

Software license Build status

Phpiredis is an extension for PHP 5.x to 8.x based on hiredis that provides a simple and efficient client for Redis and a fast incremental parser / serializer for the RESP protocol.

Installation

Building and using this extension requires hiredis (>=0.14, >=1.0) to be installed on the system. hiredis is usually available in the repositories of most Linux distributions, alternatively it is possible to build it by fetching the code from its repository.

git clone https://github.com/nrk/phpiredis.git
cd phpiredis
phpize && ./configure --enable-phpiredis
make && make install

When the configuration script is unable to locate hiredis on your system, you can specify in which directory it can be found using --with-hiredis-dir= (e.g. --with-hiredis-dir=/usr/local).

Phpiredis provides a basic test suite that can be launched with make test. Tests require a running instance of redis-server listening on 127.0.0.1:6379 but make sure that your server does not hold data you are interested: you could end up losing everything stored on it!

If you notice a failing test or a bug, you can contribute by opening a pull request on GitHub or simply file a bug on our issue tracker.

Usage

Connecting to Redis is as simple as calling the phpiredis_connect() function with a server address as the first parameter and an optional port number when the server is listening to a different port than the default 6379:

$redis = phpiredis_connect('127.0.0.1', 6379);      // normal connection
$redis = phpiredis_pconnect('127.0.0.1', 6379);     // persistent connection

Alternatively you can connect to redis using UNIX domain socket connections.

$redis = phpiredis_connect('/tmp/redis.sock');      // normal connection
$redis = phpiredis_pconnect('/tmp/redis.sock');     // persistent connection

Once the connection is established, you can send commands to Redis using phpiredis_command_bs() or pipeline them using phpiredis_multi_command_bs():

$response = phpiredis_command_bs($redis, array('DEL', 'test'));

$response = phpiredis_multi_command_bs($redis, array(
    array('SET', 'test', '1'),
    array('GET', 'test'),
));

The _bs suffix indicates that these functions can handle binary key names or values by using the unified Redis protocol available since Redis >= 1.2.

Commands can still be sent using the old and deprecated inline protocol using phpiredis_command() and phpiredis_multi_command() (note the lack of the _bs suffix) but it's highly discouraged and these functions will be removed in future versions of phpiredis.

$response = phpiredis_command($redis, 'DEL test');

$response = phpiredis_multi_command($redis, array(
    'SET test 1',
    'GET test',
));

Contributing

Any kind of contribution is extremely welcome! Just fork the project on GitHub, work on new features or bug fixes using feature branches and open pull-requests with concise but complete descriptions of your changes. If you are unsure about a proposal, you can just open an issue to discuss it before writing actual code.

Authors

Daniele Alessandri (current maintainer) Sebastian Waisbrot (original developer)

License

The code for phpiredis is distributed under the terms of the BSD license (see LICENSE).

More Repositories

1

redis-lua

A Lua client library for the redis key value storage system.
Lua
720
star
2

predis-async

Asynchronous PHP client library for Redis built on top of ReactPHP
PHP
365
star
3

mercury

... because Sinatra is not the only one performing on the stage.
Lua
102
star
4

PredisServiceProvider

Predis service provider for the Silex microframework
PHP
68
star
5

hige

{{growing mustaches in your templates with Lua}}
Lua
34
star
6

redis-rdb

A set of utilities to handle Redis .rdb files with Ruby.
Ruby
34
star
7

lamestnews

Lamest News is a port to PHP of the application that powers Lamer News.
PHP
25
star
8

monolog-fluent

A simple Monolog handler for Fluent
PHP
20
star
9

ironruby-hpricot

A port of Hpricot to IronRuby
C#
9
star
10

ironruby-json

A port of Florian Frank's json library to IronRuby
C#
9
star
11

hpricot-pure

Simply Hpricot, just made "pure".
Ruby
6
star
12

bencoder

A Bencode serializer and deserializer in pure PHP.
PHP
5
star
13

couchdb-lua-viewserver

A CouchDB view server that allows writing view functions in Lua
Lua
5
star
14

couchdb-io-viewserver

This is an experiment for a CouchDB view server implemented in the Io language just for the fun of it.
Io
5
star
15

lazybag

Lazy values for lazy tables.
Lua
4
star
16

rayak

IronRuby + Kayak HTTP server + Rack
Ruby
3
star
17

niseredis

Niseredis will make a fool of you by trying its best to mimic Redis.
PHP
2
star
18

nrk.github.com

My GitHub homepage
2
star
19

PBKDF2ServiceProvider

Password-Based Key Derivation Function (PBKDF2) service provider for the Silex microframework
PHP
2
star
20

macchiato

From CoffeeScript to JavaScript, passing through PHP while sipping a Macchiato...
PHP
1
star