Skip to content

Instantly share code, notes, and snippets.

@leapar
Last active March 22, 2018 07:48
Show Gist options
  • Save leapar/671ba723c5ba4952063777a4d3c6990b to your computer and use it in GitHub Desktop.
Save leapar/671ba723c5ba4952063777a4d3c6990b to your computer and use it in GitHub Desktop.
"github.com/garyburd/redigo/redis"
redisPool := &redis.Pool{
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", "0.0.0.0:6379")
if err != nil {
return nil, err
}
if len("") > 0 {
if _, err := c.Do("AUTH", ""); err != nil {
c.Close()
return nil, err
}
}
if len("0") > 0 {
if _, err := c.Do("SELECT", "0"); err != nil {
c.Close()
return nil, err
}
}
return c, nil
},
}
pool := redisPool.Get()
if pool == nil {
return
}
defer pool.Close()
i,e := pool.Do("SET","123456789","{sdsddsdsdsd}")
fmt.Println(i,e)
i,e = pool.Do("GET","1234567811111111")
fmt.Println(i,e)
i,e = redis.String(i,e)
fmt.Println(i,e)
i,e = pool.Do("GET","123456789")
i,e = redis.String(i,e)
fmt.Println(i,e)
i,e = pool.Do("SADD","123456789_1",1)
fmt.Println(i,e)
i,e = pool.Do("SADD","123456789_1",2)
fmt.Println(i,e)
i,e = pool.Do("SADD","123456789_1",3)
fmt.Println(i,e)
i,e = pool.Do("SISMEMBER","123456789_1",3)
fmt.Println(i,e)
i,e = redis.Bool(i,e)
fmt.Println(i,e)
i,e = pool.Do("SMEMBERS", "123456789_1")
fmt.Println(i,e)
ii,e := redis.Values(i,e)
for _, value := range ii {
i,e = redis.Int64(value,nil)
fmt.Println(i,e)
//fmt.Println(key)
}
// i,e = pool.Do("ZADD","123456789_12",0,"redis0")
// fmt.Println(i,e)
i,e = pool.Do("ZADD","123456789_12",1,"redis1")
fmt.Println(i,e)
i,e = pool.Do("ZADD","123456789_12",2,"redis2")
fmt.Println(i,e)
i,e = pool.Do("ZRANGE","123456789_12",0,3,"WITHSCORES")
fmt.Println(i,e)
ii,e = redis.Values(i,e)
for _, value := range ii {
i,e = redis.String(value,nil)
fmt.Println(i,e)
//fmt.Println(key)
}
i,e = pool.Do("ZRANGEBYSCORE","123456789_12",3,3)
fmt.Println(i,e)
ii,e = redis.Values(i,e)
for _, value := range ii {
i,e = redis.String(value,nil)
fmt.Println(i,e)
//fmt.Println(key)
}
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment