-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ type Config struct { | |
Token string | ||
ChannelId string | ||
ChatId string | ||
ConnectionURL string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ const ( | |
PROVIDER_DISCORD="discord" | ||
PROVIDER_TELEGRAM="telegram" | ||
PROVIDER_GOOGLE="google" | ||
PROVIDER_REDIS="redis" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## Introduction | ||
|
||
Redis is an in-memory data structure store, often used as a database, cache, and message broker. One of its powerful features is the Publish/Subscribe (Pub/Sub) messaging paradigm, which allows messages to be sent between clients without a direct connection between them. | ||
|
||
## What is Redis Pub/Sub? | ||
|
||
Redis Pub/Sub is a messaging pattern that enables message broadcasting. In this model, publishers send messages to channels, and subscribers listen for messages on those channels. This decouples the sender (publisher) from the receivers (subscribers), allowing for a flexible and scalable messaging system. | ||
|
||
### Key Concepts: | ||
|
||
- **Publisher**: A client that sends messages to one or more channels. | ||
- **Subscriber**: A client that listens for messages on specific channels. | ||
- **Channel**: A named entity that subscribers can subscribe to in order to receive messages. | ||
|
||
## Use Cases | ||
|
||
Redis Pub/Sub is suitable for various applications, including: | ||
|
||
- Real-time messaging systems (e.g., chat applications). | ||
- Event-driven architectures where events trigger actions. | ||
- Notifications and alerts in web applications. | ||
- Live updates in collaborative applications (e.g., document editing). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package providers | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/redis/go-redis/v9" | ||
"github.com/tech-thinker/chatz/config" | ||
) | ||
|
||
type RedisProvider struct { | ||
config *config.Config | ||
} | ||
|
||
func (agent *RedisProvider) Post(message string) (interface{}, error) { | ||
options, err := redis.ParseURL(agent.config.ConnectionURL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rdb := redis.NewClient(options) | ||
ctx := context.Background() | ||
|
||
_, err = rdb.Ping(ctx).Result() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = rdb.Publish(ctx, agent.config.ChannelId, message).Err() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return "Published", nil | ||
} | ||
|
||
func (agent *RedisProvider) Reply(threadId string, message string) (interface{}, error) { | ||
fmt.Println("Reply to discord not supported yet.") | ||
return nil, errors.New("Reply to discord not supported yet.") | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters