Giter VIP home page Giter VIP logo

Comments (7)

zishang520 avatar zishang520 commented on July 22, 2024 7

@zishang520, Are there any plans to add?

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.

from socket.io.

zishang520 avatar zishang520 commented on July 22, 2024

Hello, currently not supported.

from socket.io.

dotX12 avatar dotX12 commented on July 22, 2024

@zishang520, Are there any plans to add?

from socket.io.

zishang520 avatar zishang520 commented on July 22, 2024

@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)
}

from socket.io.

shitingbao avatar shitingbao commented on July 22, 2024

I try BroadcastWithAck function ,get "operation has timed out",

io.To(socket.Room(da["room"].(string))).Timeout(1000*time.Millisecond).Emit("test", da["message"], func(msg []any, err error) {log.Println(msg, err)})

this is my code https://github.com/shitingbao/socket.io_go/blob/main/example/adapter.go
and I tried to implement this process myself and had the same problem,code myself https://github.com/shitingbao/socket.io_go/blob/main/example/redis_adapter_example.go,I find local function not
implement Ack function in BroadcastWith,this will result in no BroadcastWithAck callback in redis adapter,because MESSAGE_BROADCAST_ACK not callback in redis subscribe

from socket.io.

zishang520 avatar zishang520 commented on July 22, 2024

There are indeed many problems and need to be refactored. Thank you for your help in testing.

from socket.io.

shitingbao avatar shitingbao commented on July 22, 2024

@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

from socket.io.

Related Issues (20)

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.