grim/wasdead

Parents 201028944eba
Children 552c093f4d6f
Added redis support to the database, right now it will just assume database 0 and localhost
  • +39 -0
    database/redis.go
  • +1 -0
    go.mod
  • +2 -0
    go.sum
  • --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/database/redis.go Sat Apr 06 00:30:43 2019 -0700
    @@ -0,0 +1,39 @@
    +package database
    +
    +import (
    + "github.com/go-redis/redis"
    +)
    +
    +type db_redis struct {
    + database *redis.Client
    +}
    +
    +func init() {
    + database := redis.NewClient(&redis.Options{
    + Addr: "localhost:6379",
    + Password: "", // no password set
    + DB: 0, // use default DB
    + })
    +
    + Register("redis", db_redis{
    + database: database,
    + })
    +}
    +
    +func (db db_redis) GetChannel(guildid string) string {
    + data, err := db.database.Get(guildid).Result()
    +
    + if err != nil {
    + return ""
    + }
    +
    + return data
    +}
    +
    +func (db db_redis) SetChannel(guildid, channel string) {
    + db.database.Set(guildid, []byte(channel), 0)
    +}
    +
    +func (db db_redis) Close() {
    + db.database.Close()
    +}
    --- a/go.mod Sat Apr 06 02:02:13 2019 -0500
    +++ b/go.mod Sat Apr 06 00:30:43 2019 -0700
    @@ -5,6 +5,7 @@
    require (
    github.com/bwmarrin/discordgo v0.19.0
    github.com/dustin/go-humanize v1.0.0
    + github.com/go-redis/redis v6.15.2+incompatible // indirect
    github.com/nicklaw5/helix v0.5.1
    github.com/prologic/bitcask v0.1.6
    )
    --- a/go.sum Sat Apr 06 02:02:13 2019 -0500
    +++ b/go.sum Sat Apr 06 00:30:43 2019 -0700
    @@ -12,6 +12,8 @@
    github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
    github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
    github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
    +github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDAhzyXg+Bs+0Sb4=
    +github.com/go-redis/redis v6.15.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
    github.com/gofrs/flock v0.7.1 h1:DP+LD/t0njgoPBvT5MJLeliUIVQR03hiKR6vezdwHlc=
    github.com/gofrs/flock v0.7.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
    github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=