Redis keyPrefix Problem
See original GitHub issue- Echo Version: 1.5.3
- Laravel Version: 5.8.*
- PHP Version: 7.2.17
- NPM Version: 6.8.0
- Node Version: 8.10.8
Description:
When Echo used with Redis, it produces keyPrefix to every channel you created. (which is by default “laravel_database_”)
Steps To Reproduce:
1-) Use Redis as Broadcast Driver and Queue Connection
BROADCAST_DRIVER=redis
QUEUE_CONNECTION=redis
2-) Create any Event
class UserRegistered implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user;
public function __construct(User $user)
{
$this->user = $user;
}
public function broadcastOn()
{
return new PrivateChannel('test');
}
public function broadcastAs()
{
return 'user.registered';
}
public function broadcastWith()
{
return ['id' => $this->user->id];
}
}
3-) Broadcast this event with Private Channel called ‘test’ 4-) Authorize this channel
Broadcast::channel('test', function ($user) {
return $user;
});
5-) Initialize Echo in your js file
import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001',
authEndpoint: "/broadcasting/auth",
});
6-) Initialize your channel
Echo.private(`test`)
.listen('.user.registered', function (e) {
console.log(e);
});
7-) Send event
event(new UserRegistered($user));
😎 See laravel-echo-server logs
[6:13:51 AM] - W3drJJWfqL9OacTmAAAa authenticated for: private-test
[6:13:51 AM] - W3drJJWfqL9OacTmAAAa joined channel: private-test
Channel: foo_bar_database_private-test
Event: user.registered
My Redis keyPrefix is “foo_bar_database_”, so the channel name that the event emitted is “foo_bar_database_private-test” but i am listening the channel “private-test”. So Echo never gets the event.
I tried to delete “private-” prefixes from both php&js side but this time Echo not requiring to authenticate channel anymore since not see as private channel.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:20 (5 by maintainers)
Top Results From Across the Web
Why spring.cache.redis.key-prefix overrides @Cacheable ...
In my application.yml, I defined a prefix for my cache keys: spring: cache: redis: key-prefix: com.example.cache.
Read more >Redis Clustering Best Practices with Multiple Keys
Learn Redis clustering best practices including the use of Redis multiple keys, Redis cluster transactions, and Redis hashtags.
Read more >Distributed Output Cache: When using 1 Redis instance for ...
Question/Problem Description. When using Redis as an Output Cache provider, the KeyPrefix is not taken into account.
Read more >Untitled
Laravel redis key prefix. ... 8 Echo laravel/echo#238 Closed using Redis driver for queue, and problem with notifications. laravel_cache is the default ...
Read more >Redis 3.2 — Query Keys and Delete Caches by Key Prefix/Pattern ...
In this case, the problem will become: How to get all keys with prefix or pattern; How to clean all caches with specific...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was able to get it working:
In config/database.php disable prefix for redis.
Now i can do
And in routes/channels.php
With redis-cli monitor 👍
And Echo clients gets their message.
As you’re using Laravel just edit your .env file and set:
REDIS_PREFIX=
This will remove the ‘foo_bar_database_’ prefix from your channel names. Then make sure you’ve restarted your services.