func TestConnMux(t *testing.T) { c, err := redistest.Dial() if err != nil { t.Fatalf("error connection to database, %v", err) } m := redisx.NewConnMux(c) defer m.Close() c1 := m.Get() c2 := m.Get() c1.Send("ECHO", "hello") c2.Send("ECHO", "world") c1.Flush() c2.Flush() s, err := redis.String(c1.Receive()) if err != nil { t.Fatal(err) } if s != "hello" { t.Fatalf("echo returned %q, want %q", s, "hello") } s, err = redis.String(c2.Receive()) if err != nil { t.Fatal(err) } if s != "world" { t.Fatalf("echo returned %q, want %q", s, "world") } c1.Close() c2.Close() }
func ExampleString() { c, err := dial() if err != nil { panic(err) } defer c.Close() c.Do("SET", "hello", "world") s, err := redis.String(c.Do("GET", "hello")) fmt.Printf("%#v\n", s) // Output: // "world" }
// This example implements ZPOP as described at // http://redis.io/topics/transactions using WATCH/MULTI/EXEC and scripting. func Example_zpop() { c, err := dial() if err != nil { fmt.Println(err) return } defer c.Close() // Add test data using a pipeline. for i, member := range []string{"red", "blue", "green"} { c.Send("ZADD", "zset", i, member) } if _, err := c.Do(""); err != nil { fmt.Println(err) return } // Pop using WATCH/MULTI/EXEC v, err := zpop(c, "zset") if err != nil { fmt.Println(err) return } fmt.Println(v) // Pop using a script. v, err = redis.String(zpopScript.Do(c, "zset")) if err != nil { fmt.Println(err) return } fmt.Println(v) // Output: // red // blue }