Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR SimpleCache doesn't actually try to connect to the cache #130

Closed
michael-grunder opened this issue Feb 26, 2024 Discussed in #129 · 1 comment · Fixed by #131
Closed

PSR SimpleCache doesn't actually try to connect to the cache #130

michael-grunder opened this issue Feb 26, 2024 Discussed in #129 · 1 comment · Fixed by #131
Labels
bug Something isn't working

Comments

@michael-grunder
Copy link
Member

Discussed in #129

Originally posted by tricarte February 23, 2024
This is a sample code connecting to Redis using relay with its PSR16 cache implementation.

<?php

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

use Relay\Relay;
use CacheWerk\Relay\Psr\SimpleCache\RelayCache;

$relay = new Relay;
$relay->connect('127.0.0.1', 6379);

echo $relay->get('some:key') . "\n"; // This line works

$cache = new RelayCache($relay);
echo $cache->get('some:key') . "\n"; // This gives 'not connected' error

This is the full error:

PHP Fatal error:  Uncaught Relay\Exception: Not connected (RELAY_ERR_IO; relay.c:3513) in /home/user/repos/relay-redis/vendor/cachewerk/relay/src/Psr/SimpleCache/RelayCache.php:43
Stack trace:
#0 /home/user/repos/relay-redis/vendor/cachewerk/relay/src/Psr/SimpleCache/RelayCache.php(43): Relay\Relay->get()
#1 /home/user/repos/relay-redis/index.php(14): CacheWerk\Relay\Psr\SimpleCache\RelayCache->get()
#2 {main}

Next CacheWerk\Relay\Psr\SimpleCache\CacheException: Not connected (RELAY_ERR_IO; relay.c:3513) in /home/user/repos/relay-redis/vendor/cachewerk/relay/src/Psr/SimpleCache/RelayCache.php:47
Stack trace:
#0 /home/user/repos/relay-redis/index.php(14): CacheWerk\Relay\Psr\SimpleCache\RelayCache->get()
#1 {main}
  thrown in /home/user/repos/relay-redis/vendor/cachewerk/relay/src/Psr/SimpleCache/RelayCache.php on line 47

So, How am I supposed to construct the RelayCache instance?

@michael-grunder michael-grunder added the bug Something isn't working label Feb 26, 2024
michael-grunder added a commit that referenced this issue Feb 26, 2024
We just want to receive the underlying `\Relay\Relay` object and use it
in the cache, not create a new one.

Fixes #130
@michael-grunder
Copy link
Member Author

The problem was we were creating a new (blank) \Relay\Relay object in our RelayCache constructor when we just wanted to use the one provided by the caller.

tillkruss pushed a commit that referenced this issue Feb 26, 2024
We just want to receive the underlying `\Relay\Relay` object and use it in the cache, not create a new one. Fixes #130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant