How to use it with redis adapter? #64
Replies: 8 comments
-
Hello, currently not supported. |
Beta Was this translation helpful? Give feedback.
-
@zishang520, Are there any plans to add? |
Beta Was this translation helpful? Give feedback.
-
This feature is currently being perfected, and I will release it as soon as it is perfected. I now need to deal with my existing work and life issues first. |
Beta Was this translation helpful? Give feedback.
-
@dotX12 I have now completed the development version of the Redis adapter, but have not proceeded with further testing yet. My evaluation may have some issues. Could you help with additional testing? go mod: https://github.com/zishang520/socket.io-go-redis demo: package main
import (
"context"
"os"
"os/signal"
"regexp"
"syscall"
"github.com/redis/go-redis/v9"
_types "github.com/zishang520/engine.io-go-parser/types"
"github.com/zishang520/engine.io/v2/types"
"github.com/zishang520/engine.io/v2/utils"
"github.com/zishang520/socket.io-go-redis/adapter"
rtypes "github.com/zishang520/socket.io-go-redis/types"
"github.com/zishang520/socket.io/v2/socket"
)
func main() {
opts := socket.DefaultServerOptions()
opts.SetAllowEIO3(true)
opts.SetCors(&types.Cors{
Origin: "*",
Credentials: true,
})
redisClient := rtypes.NewRedisClient(context.Background(), redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Username: "",
Password: "",
DB: 0,
}))
redisClient.On("error", func(errors ...any) {
utils.Log().Error("Error: %v", errors)
})
opts.SetAdapter(&adapter.RedisAdapterBuilder{
Redis: redisClient,
Opts: &adapter.RedisAdapterOptions{},
})
httpServer := types.NewWebServer(nil)
socketio := socket.NewServer(httpServer, opts)
socketio.Of(
regexp.MustCompile(`/\w+`),
nil,
).Use(func(client *socket.Socket, next func(*socket.ExtendedError)) {
next(nil)
}).On("connection", func(clients ...interface{}) {
client := clients[0].(*socket.Socket)
client.On("event", func(clients ...interface{}) {
client.Emit("event", map[string]interface{}{
"message": _types.NewStringBufferString("event"),
})
})
})
httpServer.Listen("127.0.0.1:3000", nil)
exit := make(chan struct{})
SignalC := make(chan os.Signal)
signal.Notify(SignalC, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
for s := range SignalC {
switch s {
case syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT:
close(exit)
return
}
}
}()
<-exit
socketio.Close(nil)
os.Exit(0)
} |
Beta Was this translation helpful? Give feedback.
-
I try
this is my code |
Beta Was this translation helpful? Give feedback.
-
There are indeed many problems and need to be refactored. Thank you for your help in testing. |
Beta Was this translation helpful? Give feedback.
-
@dotX12 @minbala I added a basic library to implement basic functions. You can try to use it first and improve it yourself, saving some repetitive work.in this https://github.com/shitingbao/socketio-go-redis-adapter |
Beta Was this translation helpful? Give feedback.
-
Thanks for your patience in this long process, the redis adapter has been released. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions