1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| package main
import ( "fmt"
"golangtest/redis" )
func main() { client := redis.GetClient()
val, err := client.HGetAll("todoitem:bbrrgade4b3gfpfecvh0").Result() fmt.Printf("%v, %v\n", val, err)
client.Set("mytestkey", 100, 0) fmt.Println(client.Get("mytestkey").Result())
client.LPush("mytestlist", 1, 2, 3, 4, 5, 100) fmt.Println(client.LPop("mytestlist").Result())
llen, _ := client.LLen("mytestlist").Result() fmt.Println(llen) fmt.Println(client.LRange("mytestlist", 0, llen).Result()) fmt.Println(client.LRange("mytestlist", 0, -1).Result())
user := map[string]interface{}{ "name": "Jhon", "age": 26, "work": "programmer", } client.HMSet("mytestuser:1", user) fmt.Println(client.HGet("mytestuser:1", "work").Result()) fmt.Println(client.HGetAll("mytestuser:1").Result())
client.SAdd("mytestset", 7, 6, 5, 4, 8, 9, 100) fmt.Println(client.SCard("mytestset").Result())
fmt.Println(client.SMembers("mytestset").Result())
result, _ := client.Keys("*").Result() fmt.Println("Redis value: ", result)
p := client.Pipeline() p.HMSet("mytestuser:2", map[string]interface{}{ "name": "Bob", "age": 26, "work": "PM", })
p.LPush("mytestuserlist", "Bob") p.Set("mytestuser:bob:age", 26, 0) p.Set("mytestusernumber", 0, 0) p.Incr("mytestusernumber") p.Exec() fmt.Println("mytestuser:2 -> ") fmt.Println(client.HGetAll("mytestuser:2").Result()) fmt.Println("mytestuserlist -> ") fmt.Println(client.LRange("mytestuserlist", 0, -1).Result()) fmt.Println("mytestusernumber -> ") fmt.Println(client.Get("mytestusernumber").Result()) fmt.Println("mytestuser:bob:age -> ") fmt.Println(client.Get("mytestuser:bob:age").Result()) }
|