Skip to content

Instantly share code, notes, and snippets.

@gabriel-tincu
Last active September 13, 2017 18:35
Show Gist options
  • Save gabriel-tincu/7d24b9333ed993b18037341d38bedeeb to your computer and use it in GitHub Desktop.
Save gabriel-tincu/7d24b9333ed993b18037341d38bedeeb to your computer and use it in GitHub Desktop.
minima redisl keyspace notification glob pattern in go
package main
import (
"fmt"
"github.com/go-redis/redis"
"time"
)
func main() {
cli_set_del := redis.NewClient(&redis.Options{
Addr:"localhost:6379",
DB:0,
})
cli_listen := redis.NewClient(&redis.Options{
Addr:"localhost:6379",
DB:0,
})
s, err := cli_set_del.ConfigSet("notify-keyspace-events", "KA").Result()
if err != nil {
panic(err)
} else {
fmt.Println(s)
}
for i:=0;i<3;i++{
ps := cli_listen.PSubscribe("__keyspace@0__:foo*")
go react(ps, i)
}
time.Sleep(time.Millisecond * 100)
for x:=1;x<5;x++ {
cli_set_del.Set(fmt.Sprintf("foo%d", x), "bar", time.Hour)
}
fmt.Println("Starting to delete crap")
for i:=1;i<5;i++{
fmt.Printf("Deleting foo%d\n",i)
cli_set_del.Del(fmt.Sprintf("foo%d", i))
time.Sleep(time.Millisecond * 300)
}
time.Sleep(1 * time.Second)
}
func react(ps *redis.PubSub, i int) {
c := ps.Channel()
for {
select {
case r := <- c:
fmt.Println(r, i)
}
}
}
@gabriel-tincu
Copy link
Author

No fanout, glob pattern, on all events on a key pattern, so we end up filtering the ones we actually need

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment