func main() { var client goredis.Client client.Set("a", []byte("hello")) val, _ := client.Get("a") fmt.Println(string(val)) client.Del("a") vals := []string{"a", "b", "c", "d", "e"} for _, v := range vals { client.Rpush("l", []byte(v)) } dbvals, _ := client.Lrange("l", 0, 4) for i, v := range dbvals { println(i, ":", string(v)) } client.Del("l") }
func main() { var client goredis.Client // 设置端口为redis默认端口 client.Addr = "127.0.0.1:6379" //字符串操作 client.Set("a", []byte("hello")) val, _ := client.Get("a") fmt.Println(string(val)) client.Del("a") //list操作 vals := []string{"a", "b", "c", "d", "e"} for _, v := range vals { client.Rpush("l", []byte(v)) } dbvals, _ := client.Lrange("l", 0, 4) for i, v := range dbvals { println(i, ":", string(v)) } client.Del("l") //hash操作 client.Hset("hash", "aaa", []byte("111")) client.Del("hash") }
func main() { var client goredis.Client // Set the default port in Redis client.Addr = DB_URL + ":" + DB_PORT // string manipulation fmt.Println("Inserting") err := client.Set("a", []byte("hello")) checkError(err) // list operation vals := []string{"a", "b", "c", "d"} for _, v := range vals { err = client.Rpush("l", []byte(v)) checkError(err) } fmt.Println("Updating") err = client.Set("a", []byte("a is for apple")) checkError(err) err = client.Rpush("l", []byte("e")) checkError(err) fmt.Println("Querying") val, err := client.Get("a") checkError(err) fmt.Println(string(val)) dbvals, err := client.Lrange("l", 0, 4) checkError(err) for i, v := range dbvals { println(i, ":", string(v)) } fmt.Println("Deleting") _, err = client.Del("l") checkError(err) _, err = client.Del("a") checkError(err) }
func main() { var client goredis.Client // NOTE: 目前该版本还不支持redis认证 client.Addr = "127.0.0.1:6379" client.Db = 4 client.Set("a", []byte("hello")) val, _ := client.Get("a") fmt.Println(string(val)) client.Del("a") vals := []string{"a", "b", "c", "d", "e"} for _, v := range vals { client.Rpush("l", []byte(v)) } dbvals, _ := client.Lrange("l", 0, 4) for i, v := range dbvals { println(i, ":", string(v)) } client.Del("l") }