mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
add examples for gredis
This commit is contained in:
@ -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...)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -16,5 +16,4 @@ func main() {
|
||||
redis.Do("SET", "k", "v")
|
||||
v, _ := redis.Do("GET", "k")
|
||||
fmt.Println(gconv.String(v))
|
||||
}
|
||||
|
||||
}
|
||||
16
geg/database/redis/gredis_conn1.go
Normal file
16
geg/database/redis/gredis_conn1.go
Normal 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))
|
||||
}
|
||||
|
||||
21
geg/database/redis/gredis_conn2.go
Normal file
21
geg/database/redis/gredis_conn2.go
Normal 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))
|
||||
}
|
||||
|
||||
24
geg/database/redis/gredis_conn3.go
Normal file
24
geg/database/redis/gredis_conn3.go
Normal 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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user