Skip to content

Instantly share code, notes, and snippets.

@guiferrpereira
Created January 8, 2015 18:26
Show Gist options
  • Save guiferrpereira/a818ae6fbae4eb8c0563 to your computer and use it in GitHub Desktop.
Save guiferrpereira/a818ae6fbae4eb8c0563 to your computer and use it in GitHub Desktop.
PeixotosGo Redis Keys PFFFF
package main
import garyredis "github.com/garyburd/redigo/redis"
import "fmt"
var pool garyredis.Pool
func PooledGet(key string) (string, error) {
conn := pool.Get()
defer conn.Close()
v, e := conn.Do("GET", key)
if e != nil {
return "", e
}
return string(v.([]uint8)), nil
}
func PooledAllKeys() ([]string, error) {
conn := pool.Get()
defer conn.Close()
v, e := conn.Do("KEYS", "*")
if e != nil {
return make([]string, 0), e
}
av := v.([]interface{})
keys := make([]string, len(av))
for i := 0; i < len(av); i++ {
keys[i] = string(av[i].([]uint8))
}
return keys, nil
}
func Redigo (keys []string, signal chan struct{}) {
for _, k := range keys {
PooledGet(k)
}
signal <- struct{}{}
}
func main () {
signal := make(chan struct{})
n := 1
pool = garyredis.Pool{
MaxIdle: 50,
MaxActive: 500, // max number of connections
Dial: func() (garyredis.Conn, error) {
return garyredis.Dial("tcp", ":6379")
},
}
keys, _ := PooledAllKeys()
for i := 0; i < n; i++ {
go Redigo(keys, signal)
}
for i := 0; i < n; i++ {
<- signal
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment