Code Monkey home page Code Monkey logo

phpiredis's Introduction

Phpiredis

Phpiredis is an extension for PHP that wraps hiredis to provide a very simple but efficient client library for Redis and a fast incremental parser for its protocol.

Installation

Building and using phpiredis requires hiredis to be installed on your system. hiredis is usually available in the repositories of the most used Linux distributions, alternatively you can build it yourself fetching the code from its canonical repository.

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

If 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 functions 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 most likely 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).

phpiredis's People

Contributors

janpieper avatar jmalloc avatar lstrojny avatar mkoppanen avatar nrk avatar seppo0010 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.