add examples for gredis

This commit is contained in:
John
2019-03-21 23:51:57 +08:00
parent 15cfd5ce5c
commit 62580b5719
5 changed files with 63 additions and 3 deletions

View File

@ -164,6 +164,7 @@ func (r *Redis) Do(command string, args ...interface{}) (interface{}, error) {
return conn.Do(command, args...)
}
// Deprecated.
// Send writes the command to the client's output buffer.
//
// 执行异步命令 - Send
@ -173,4 +174,3 @@ func (r *Redis) Send(command string, args ...interface{}) error {
return conn.Send(command, args...)
}

View File

@ -16,5 +16,4 @@ func main() {
redis.Do("SET", "k", "v")
v, _ := redis.Do("GET", "k")
fmt.Println(gconv.String(v))
}
}

View File

@ -0,0 +1,16 @@
package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/util/gconv"
)
func main() {
conn := g.Redis().Conn()
defer conn.Close()
conn.Do("SET", "k", "v")
v, _ := conn.Do("GET", "k")
fmt.Println(gconv.String(v))
}

View File

@ -0,0 +1,21 @@
package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/util/gconv"
)
func main() {
conn := g.Redis().Conn()
defer conn.Close()
conn.Send("SET", "foo", "bar")
conn.Send("GET", "foo")
conn.Flush()
// reply from SET
conn.Receive()
// reply from GET
v, _ := conn.Receive()
fmt.Println(gconv.String(v))
}

View File

@ -0,0 +1,24 @@
package main
import (
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/util/gconv"
)
func main() {
conn := g.Redis().Conn()
defer conn.Close()
_, err := conn.Do("SUBSCRIBE", "channel")
if err != nil {
panic(err)
}
for {
reply, err := conn.Receive()
if err != nil {
panic(err)
}
fmt.Println(gconv.Strings(reply))
}
}