GithubHelp home page GithubHelp logo

go-joe / redis-memory Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 35 KB

Redis integration for the Joe bot library

Home Page: https://github.com/go-joe/joe

License: BSD 3-Clause "New" or "Revised" License

Go 100.00%
joe slack chat bot chatbot-framework

redis-memory's Introduction

Joe Bot - Redis Memory

Integrating Joe with Redis. https://github.com/go-joe/joe


This repository contains a module for the Joe Bot library.

Getting Started

This library is packaged as Go module. You can get it via:

go get github.com/go-joe/redis-memory

Example usage

In order to connect your bot to Redis you can simply pass it as module when creating a new bot:

package main

import (
	"github.com/go-joe/joe"
	"github.com/go-joe/redis-memory"
	"github.com/pkg/errors"
)

type ExampleBot struct {
	*joe.Bot
}

func main() {
	b := &ExampleBot{
		Bot: joe.New("example",
			redis.Memory("localhost:6379"),
		),
	}

	b.Respond("remember (.+) is (.+)", b.Remember)
	b.Respond("what is (.+)", b.WhatIs)
	b.Respond("show keys", b.ShowKeys)

	err := b.Run()
	if err != nil {
		b.Logger.Fatal(err.Error())
	}
}

func (b *ExampleBot) Remember(msg joe.Message) error {
	key, value := msg.Matches[0], msg.Matches[1]
	msg.Respond("OK, I'll remember %s is %s", key, value)
	return b.Store.Set(key, value)
}

func (b *ExampleBot) WhatIs(msg joe.Message) error {
	key := msg.Matches[0]
	var value string
	ok, err := b.Store.Get(key, &value)
	if err != nil {
		return errors.Wrapf(err, "failed to retrieve key %q from brain", key)
	}

	if ok {
		msg.Respond("%s is %s", key, value)
	} else {
		msg.Respond("I do not remember %q", key)
	}

	return nil
}

func (b *ExampleBot) ShowKeys(msg joe.Message) error {
	keys, err := b.Store.Keys()
	if err != nil {
		return err
	}

	msg.Respond("I got %d keys:", len(keys))
	for i, k := range keys {
		msg.Respond("%d) %q", i+1, k)
	}
	return nil
}

Built With

  • go-redis - redis client in Go
  • redimock - redis mock library in tcp level
  • testify - A simple unit test library
  • zap - Blazing fast, structured, leveled logging in Go

Contributing

If you want to hack on this repository, please read the short CONTRIBUTING.md guide first.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Friedrich Große - Initial work - fgrosse

See also the list of contributors who participated in this project.

License

This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.

Acknowledgments

  • embedmd for a cool tool to embed source code in markdown files

redis-memory's People

Contributors

fgrosse avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

snero

redis-memory's Issues

Keys

Reading through the code, should memory.Keys be calling HKeys instead of Keys?

go get redis-memory gives error

Hi,

i get the following error

➜  visibility go get github.com/go-joe/redis-memory
# github.com/go-joe/redis-memory
../../../github.com/go-joe/redis-memory/memory.go:80:30: not enough arguments in call to memory.Client.cmdable.Ping
        have ()
        want (context.Context)
../../../github.com/go-joe/redis-memory/memory.go:92:25: cannot use b.hkey (type string) as type context.Context in argument to b.Client.cmdable.HSet:
        string does not implement context.Context (missing Deadline method)
../../../github.com/go-joe/redis-memory/memory.go:98:27: not enough arguments in call to b.Client.cmdable.HGet
        have (string, string)
        want (context.Context, string, string)
../../../github.com/go-joe/redis-memory/memory.go:111:29: cannot use b.hkey (type string) as type context.Context in argument to b.Client.cmdable.HDel:
        string does not implement context.Context (missing Deadline method)
../../../github.com/go-joe/redis-memory/memory.go:117:23: not enough arguments in call to b.Client.cmdable.HKeys
        have (string)
        want (context.Context, string)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.