https://github.com/zishang520/socket.io-go-redis
You can use the redis function happily
https://github.com/zishang520/socket.io-go-redis
Last synced: 3 months ago
JSON representation
You can use the redis function happily
- Host: GitHub
- URL: https://github.com/zishang520/socket.io-go-redis
- Owner: zishang520
- License: mit
- Created: 2023-07-28T09:44:25.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-08T03:56:30.000Z (6 months ago)
- Last Synced: 2025-04-08T04:28:50.161Z (6 months ago)
- Language: Go
- Homepage:
- Size: 91.8 KB
- Stars: 5
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# socket.io-go-redis
[](https://github.com/zishang520/socket.io-go-redis/actions/workflows/go.yml)
[](https://pkg.go.dev/github.com/zishang520/socket.io-go-redis)## How to use
```golang
package mainimport (
"context"
"fmt"
"os"
"os/signal"
"syscall""github.com/redis/go-redis/v9"
s "github.com/zishang520/engine.io/v2/types"
"github.com/zishang520/socket.io-go-redis/adapter"
"github.com/zishang520/socket.io-go-redis/types"
"github.com/zishang520/socket.io/v2/socket"
// "github.com/zishang520/socket.io-go-redis/emitter"
)func main() {
redisClient := types.NewRedisClient(context.TODO(), redis.NewClient(&redis.Options{
Addr: "127.0.0.1:6379",
Username: "",
Password: "",
DB: 0,
}))redisClient.On("error", func(a ...any) {
fmt.Println(a)
})config := socket.DefaultServerOptions()
config.SetAdapter(&adapter.RedisAdapterBuilder{
Redis: redisClient,
Opts: &adapter.RedisAdapterOptions{},
})
httpServer := s.CreateServer(nil)
io := socket.NewServer(httpServer, config)
io.On("connection", func(clients ...any) {
client := clients[0].(*socket.Socket)
client.On("event", func(datas ...any) {
})
client.On("disconnect", func(...any) {
})
})
httpServer.Listen("127.0.0.1:9000", nil)// emitter.NewEmitter(redisClient, nil, "/web") // more ....
exit := make(chan struct{})
SignalC := make(chan os.Signal)signal.Notify(SignalC, os.Interrupt, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
for s := range SignalC {
switch s {
case os.Interrupt, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT:
close(exit)
return
}
}
}()<-exit
httpServer.Close(nil)
os.Exit(0)
}
```## Tests
Standalone tests can be run with `make test` which will run the golang tests.
You can run the tests locally using the following command:
```
make test
```## Support
[issues](https://github.com/zishang520/socket.io-go-redis/issues)
## Development
To contribute patches, run tests or benchmarks, make sure to clone the
repository:```bash
git clone git://github.com/zishang520/socket.io-go-redis.git
```Then:
```bash
cd socket.io-go-redis
make test
```See the `Tests` section above for how to run tests before submitting any patches.
## License
MIT