Simple Redis
Easy way to use Redis from Go.
Dependencies
Requires Go 1.17 or later.
Online API Documentation
godoc.org
Features and limitations
- Supports simple use of lists, hashmaps, sets and key/values
- Deals mainly with strings
- Uses the redigo package
Example usage
package main
import (
"log"
"github.com/xyproto/simpleredis/v2"
)
func main() {
if err := simpleredis.TestConnection(); err != nil {
log.Fatalln("Could not connect to Redis. Is the service up and running?")
}
pool := simpleredis.NewConnectionPool()
defer pool.Close()
list := simpleredis.NewList(pool, "greetings")
if list.Add("hello") != nil {
log.Fatalln("Could not add an item to list!")
}
if item, err := list.GetLast(); err != nil {
log.Fatalln("Could not fetch the last item from the list!")
} else {
log.Println("The value of the stored item is:", item)
}
if list.Remove() != nil {
log.Fatalln("Could not remove the list!")
}
}
Testing
Redis must be up and running locally for the go test
tests to work.
Timeout issues
If there are timeout issues when connecting to Redis, try consulting the Redis latency doctor on the server by running redis-cli
and then latency doctor
.
Version, license and author