diff --git a/g/database/gredis/gredis.go b/g/database/gredis/gredis.go index de9c9f034..dc2151a8a 100644 --- a/g/database/gredis/gredis.go +++ b/g/database/gredis/gredis.go @@ -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...) } - diff --git a/geg/database/redis/gredis.go b/geg/database/redis/gredis.go index 48d2acfa3..8fff3251e 100644 --- a/geg/database/redis/gredis.go +++ b/geg/database/redis/gredis.go @@ -16,5 +16,4 @@ func main() { redis.Do("SET", "k", "v") v, _ := redis.Do("GET", "k") fmt.Println(gconv.String(v)) -} - +} \ No newline at end of file diff --git a/geg/database/redis/gredis_conn1.go b/geg/database/redis/gredis_conn1.go new file mode 100644 index 000000000..b900ebe1e --- /dev/null +++ b/geg/database/redis/gredis_conn1.go @@ -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)) +} + diff --git a/geg/database/redis/gredis_conn2.go b/geg/database/redis/gredis_conn2.go new file mode 100644 index 000000000..0c7b1348d --- /dev/null +++ b/geg/database/redis/gredis_conn2.go @@ -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)) +} + diff --git a/geg/database/redis/gredis_conn3.go b/geg/database/redis/gredis_conn3.go new file mode 100644 index 000000000..a4d0185d8 --- /dev/null +++ b/geg/database/redis/gredis_conn3.go @@ -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)) + } +} +