Search by

spiral / roadrunner-kv

wolfy-j

PSR-16 cache on top of the RoadRunner Key-Value plugin storages (memory, boltdb, redis, memcached) over RPC

Package info

github.com/roadrunner-php/kv

Homepage

Issues

Chat

Documentation

pkg:composer/spiral/roadrunner-kv

Fund package maintenance!

roadrunner-server

Statistics

Installs: 5 000 484

Dependents: 11

Suggesters: 0

Stars: 11


README

RoadRunner

PSR-16 cache on top of the RoadRunner KV plugin

Documentation Sponsor

Psalm Level Type Coverage Mutation testing badge


This package lets a PHP application use the storages of the RoadRunner KV plugin (memory, boltdb, redis, memcached and others) as a PSR-16 cache, talking to RoadRunner over RPC.

Get Started

Installation

composer require roadrunner/kv

PHP Latest Version on Packagist License Total Downloads

You can use the convenient installer to download the latest available compatible version of RoadRunner server:

composer require roadrunner/cli --dev
vendor/bin/rr get

Configuration

First you need to add at least one kv plugin to your roadrunner configuration. For example, such a configuration would be quite feasible to run:

rpc:
  listen: tcp://127.0.0.1:6001

kv:
  test:
    driver: memory
    config:
        interval: 10

Note

Read more about all available drivers on the documentation page.

After starting the server with this configuration, one driver named "test" will be available to you.

Usage

The following code will allow writing and reading an arbitrary value from the RoadRunner server.

<?php

use Spiral\Goridge\RPC\RPC;
use Spiral\RoadRunner\KeyValue\Factory;

require __DIR__ . '/vendor/autoload.php';

$factory = new Factory(RPC::create('tcp://127.0.0.1:6001'));

$cache = $factory->select('test');

// After that you can write and read arbitrary values:

$cache->set('key', 'value');

echo $cache->get('key'); // string(5) "value"

Serialization

Values are serialized with PHP's native serialize() by default. Pass another serializer to the factory to change that:

  • IgbinarySerializer — requires the igbinary extension;
  • SodiumSerializer — encrypts values produced by an inner serializer with a keypair from sodium_crypto_box_keypair(), requires the sodium extension.
use Spiral\RoadRunner\KeyValue\Factory;
use Spiral\RoadRunner\KeyValue\Serializer\DefaultSerializer;
use Spiral\RoadRunner\KeyValue\Serializer\SodiumSerializer;

$factory = new Factory($rpc, new SodiumSerializer(new DefaultSerializer(), $key));
try Spiral Framework