redis
This commit is contained in:
parent
6cd47cc75c
commit
b27db22cba
4
README
4
README
@ -1,4 +1,5 @@
|
|||||||
= next
|
= next
|
||||||
|
get better at go
|
||||||
write blog post on Go on Heroku
|
write blog post on Go on Heroku
|
||||||
market blog post on Go on Heroku
|
market blog post on Go on Heroku
|
||||||
proof ebook toolchain
|
proof ebook toolchain
|
||||||
@ -59,7 +60,7 @@ gobyexample.com signups
|
|||||||
* http streaming server
|
* http streaming server
|
||||||
* http streaming client
|
* http streaming client
|
||||||
* http proxy
|
* http proxy
|
||||||
* postgres, redis
|
* postgres
|
||||||
* templating
|
* templating
|
||||||
* web app
|
* web app
|
||||||
* hipache port
|
* hipache port
|
||||||
@ -82,3 +83,4 @@ gobyexample.com signups
|
|||||||
* time
|
* time
|
||||||
* string to/from numbers
|
* string to/from numbers
|
||||||
* oauth for google domains
|
* oauth for google domains
|
||||||
|
* connection pool
|
||||||
|
@ -3,22 +3,67 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fzzbt/radix/redis"
|
"github.com/fzzbt/radix/redis"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// initialize
|
||||||
conf := redis.DefaultConfig()
|
conf := redis.DefaultConfig()
|
||||||
client := redis.NewClient(conf)
|
client := redis.NewClient(conf)
|
||||||
fmt.Println(conf)
|
fmt.Println(conf)
|
||||||
fmt.Println(client)
|
fmt.Println(client)
|
||||||
|
|
||||||
|
// set & get
|
||||||
setRep := client.Set("foo", "bar")
|
setRep := client.Set("foo", "bar")
|
||||||
if setRep.Err != nil { panic(setRep.Err) }
|
if setRep.Err != nil { panic(setRep.Err) }
|
||||||
fmt.Println(setRep)
|
fmt.Println(setRep)
|
||||||
|
|
||||||
getRep := client.Get("foo")
|
getRep := client.Get("foo")
|
||||||
if getRep.Err != nil { panic(getRep.Err) }
|
if getRep.Err != nil { panic(getRep.Err) }
|
||||||
getStr, _ := getRep.Str()
|
getStr, _ := getRep.Str()
|
||||||
|
|
||||||
fmt.Println(getRep)
|
fmt.Println(getRep)
|
||||||
fmt.Println(getStr)
|
fmt.Println(getStr)
|
||||||
|
|
||||||
|
// varadic calls
|
||||||
|
client.Set("foo1", "bar1")
|
||||||
|
client.Set("foo2", "bar2")
|
||||||
|
client.Set("foo3", "bar3")
|
||||||
|
mgetRep := client.Mget("foo1", "foo2", "foo3")
|
||||||
|
fmt.Println(mgetRep)
|
||||||
|
|
||||||
|
// multi calls
|
||||||
|
mcallRep := client.MultiCall(func(mc *redis.MultiCall) {
|
||||||
|
mc.Set("k1", "v1")
|
||||||
|
mc.Get("k1")
|
||||||
|
})
|
||||||
|
if mcallRep.Err != nil { panic(mcallRep.Err) }
|
||||||
|
mcallVal, _ := mcallRep.Elems[1].Str()
|
||||||
|
fmt.Println(mcallVal)
|
||||||
|
|
||||||
|
// transactional calls
|
||||||
|
tranRep := client.Transaction(func(mc *redis.MultiCall) {
|
||||||
|
mc.Set("k2", "v2")
|
||||||
|
mc.Get("k2")
|
||||||
|
})
|
||||||
|
if tranRep.Err != nil { panic(tranRep.Err) }
|
||||||
|
tranStr, _ := tranRep.Elems[1].Str()
|
||||||
|
fmt.Println(tranStr)
|
||||||
|
|
||||||
|
// pubsub
|
||||||
|
msgHdlr := func(msg *redis.Message) {
|
||||||
|
fmt.Println(msg)
|
||||||
}
|
}
|
||||||
|
sub, subErr := client.Subscription(msgHdlr)
|
||||||
|
if subErr != nil { panic(subErr) }
|
||||||
|
defer sub.Close()
|
||||||
|
sub.Subscribe("chan1", "chan2")
|
||||||
|
sub.Psubscribe("chan*")
|
||||||
|
client.Publish("chan1", "foo")
|
||||||
|
sub.Unsubscribe("chan1")
|
||||||
|
client.Publish("chan2", "bar")
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
// $ redis-server
|
||||||
|
// $ cd xx-redis
|
||||||
|
// $ go get
|
||||||
|
// $ ./xx-redis
|
||||||
|
Loading…
x
Reference in New Issue
Block a user