Skip to content

Instantly share code, notes, and snippets.

@maguec
Created August 2, 2021 17:05
Show Gist options
  • Save maguec/40830881581d6c2158221cf8d3567ef5 to your computer and use it in GitHub Desktop.
Save maguec/40830881581d6c2158221cf8d3567ef5 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/gomodule/redigo/redis"
)
func main() {
pool := &redis.Pool{
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", "localhost:6379")
if err != nil {
return nil, err
}
return c, err
},
}
client := pool.Get()
defer client.Close()
_, err := client.Do("SET", "mykey", "Hello from redigo!")
if err != nil {
panic(err)
}
value, err := client.Do("GET", "mykey")
if err != nil {
panic(err)
}
fmt.Printf("%s \n", value)
_, err = client.Do("ZADD", "vehicles", 4, "car")
if err != nil {
panic(err)
}
_, err = client.Do("ZADD", "vehicles", 2, "bike")
if err != nil {
panic(err)
}
vehicles, err := client.Do("ZRANGE", "vehicles", 0, -1, "WITHSCORES")
if err != nil {
panic(err)
}
fmt.Printf("%s \n", vehicles)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment