Skip to content

Commit 7464de5

Browse files
authored
Merge pull request #13 from BryceWayne/copilot/sub-pr-12
Resolve merge conflicts between feature and root branches
2 parents f8784fc + 8f41e77 commit 7464de5

1 file changed

Lines changed: 89 additions & 2 deletions

File tree

README.md

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,49 @@ func main() {
5555
}
5656
```
5757

58-
## PubSub Usage (Canonical Example)
58+
## PubSub Usage
5959

6060
MemoryStore supports an agnostic PubSub interface. By default, it uses an in-memory implementation. To use Google Cloud PubSub, simply provide your Project ID configuration.
6161

62+
### Using In-Memory PubSub (Default)
63+
64+
```go
65+
package main
66+
67+
import (
68+
"log"
69+
"time"
70+
"github.com/BryceWayne/MemoryStore/memorystore"
71+
)
72+
73+
func main() {
74+
store := memorystore.NewMemoryStore()
75+
defer store.Stop()
76+
77+
// Subscribe to a topic
78+
msgs, err := store.Subscribe("user-updates")
79+
if err != nil {
80+
log.Fatal(err)
81+
}
82+
83+
// Listen in background
84+
go func() {
85+
for msg := range msgs {
86+
log.Printf("Received: %s", string(msg))
87+
}
88+
}()
89+
90+
// Publish to the topic
91+
err = store.Publish("user-updates", []byte("User 123 logged in"))
92+
if err != nil {
93+
log.Fatal(err)
94+
}
95+
96+
// Give time for message delivery
97+
time.Sleep(1 * time.Second)
98+
}
99+
```
100+
62101
### Using Google Cloud PubSub
63102

64103
```go
@@ -170,6 +209,35 @@ metrics := store.GetMetrics()
170209
log.Printf("Hits: %d, Misses: %d, Items: %d", metrics.Hits, metrics.Misses, metrics.Items)
171210
```
172211

212+
### Expiration and Cleanup
213+
214+
Keys automatically expire after their specified duration:
215+
216+
```go
217+
// Set a value that expires in 5 seconds
218+
store.Set("temp", []byte("temporary value"), 5*time.Second)
219+
220+
// The background cleanup routine will automatically remove expired items
221+
// You can also manually check if an item exists
222+
time.Sleep(6 * time.Second)
223+
if _, exists := store.Get("temp"); !exists {
224+
log.Println("Key has expired")
225+
}
226+
```
227+
228+
### Proper Shutdown
229+
230+
Always ensure proper cleanup by calling `Stop()`:
231+
232+
```go
233+
store := memorystore.NewMemoryStore()
234+
defer func() {
235+
if err := store.Stop(); err != nil {
236+
log.Printf("Error stopping store: %v", err)
237+
}
238+
}()
239+
```
240+
173241
## Performance Considerations
174242

175243
- Uses `github.com/goccy/go-json` for faster JSON operations
@@ -194,8 +262,27 @@ make bench
194262

195263
## Contributing
196264

197-
Contributions are welcome! Please feel free to submit a Pull Request.
265+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
266+
267+
1. Fork the repository
268+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
269+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
270+
4. Push to the branch (`git push origin feature/AmazingFeature`)
271+
5. Open a Pull Request
198272

199273
## License
200274

201275
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
276+
277+
## Acknowledgments
278+
279+
- Thanks to the Go team for the amazing standard library
280+
- [go-json](https://github.com/goccy/go-json) for high-performance JSON operations
281+
282+
## Support
283+
284+
If you have any questions or need help integrating MemoryStore, please:
285+
286+
1. Check the [documentation](https://godoc.org/github.com/BryceWayne/MemoryStore)
287+
2. Open an issue with a detailed description
288+
3. Reach out through the discussions tab

0 commit comments

Comments
 (0)