Add other redigo demo
This commit is contained in:
85
es/05.6.md
85
es/05.6.md
@@ -9,11 +9,90 @@ Al ser el lenguaje C del siglo XXI, Go tiene soporte para bases de datos NoSQL,
|
|||||||
redis es un sistema de almacenamiento llave valor como Memcached, que soporta los tipos de cadenas, listas conjuntos y conjuntos ordenados.
|
redis es un sistema de almacenamiento llave valor como Memcached, que soporta los tipos de cadenas, listas conjuntos y conjuntos ordenados.
|
||||||
|
|
||||||
Aquí están algunos de los manejadores de bases de datos para redis:
|
Aquí están algunos de los manejadores de bases de datos para redis:
|
||||||
|
- [https://github.com/garyburd/redigo](https://github.com/garyburd/redigo)
|
||||||
|
- [https://github.com/go-redis/redis](https://github.com/go-redis/redis)
|
||||||
|
- [https://github.com/hoisie/redis](https://github.com/hoisie/redis)
|
||||||
- [https://github.com/alphazero/Go-Redis](https://github.com/alphazero/Go-Redis)
|
- [https://github.com/alphazero/Go-Redis](https://github.com/alphazero/Go-Redis)
|
||||||
- [http://code.google.com/p/tideland-rdc/](http://code.google.com/p/tideland-rdc/)
|
|
||||||
- [https://github.com/simonz05/godis](https://github.com/simonz05/godis)
|
- [https://github.com/simonz05/godis](https://github.com/simonz05/godis)
|
||||||
- [https://github.com/hoisie/redis.go](https://github.com/hoisie/redis.go)
|
|
||||||
|
Let's see how to use the driver that redigo to operate on a database:
|
||||||
|
|
||||||
|
```Go
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/garyburd/redigo/redis"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Pool *redis.Pool
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
redisHost := ":6379"
|
||||||
|
Pool = newPool(redisHost)
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPool(server string) *redis.Pool {
|
||||||
|
|
||||||
|
return &redis.Pool{
|
||||||
|
|
||||||
|
MaxIdle: 3,
|
||||||
|
IdleTimeout: 240 * time.Second,
|
||||||
|
|
||||||
|
Dial: func() (redis.Conn, error) {
|
||||||
|
c, err := redis.Dial("tcp", server)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c, err
|
||||||
|
},
|
||||||
|
|
||||||
|
TestOnBorrow: func(c redis.Conn, t time.Time) error {
|
||||||
|
_, err := c.Do("PING")
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func close() {
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt)
|
||||||
|
signal.Notify(c, syscall.SIGTERM)
|
||||||
|
signal.Notify(c, syscall.SIGKILL)
|
||||||
|
go func() {
|
||||||
|
<-c
|
||||||
|
Pool.Close()
|
||||||
|
os.Exit(0)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func Get(key string) ([]byte, error) {
|
||||||
|
|
||||||
|
conn := Pool.Get()
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
var data []byte
|
||||||
|
data, err := redis.Bytes(conn.Do("GET", key))
|
||||||
|
if err != nil {
|
||||||
|
return data, fmt.Errorf("error get key %s: %v", key, err)
|
||||||
|
}
|
||||||
|
return data, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
test, err := Get("test")
|
||||||
|
fmt.Println(test, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
Realicé una bifurcación de el último de estos paquetes, arreglé algunos servicios y lo usé en mi sistema de acortado de urls (2 millones de peticiones por día).
|
Realicé una bifurcación de el último de estos paquetes, arreglé algunos servicios y lo usé en mi sistema de acortado de urls (2 millones de peticiones por día).
|
||||||
|
|
||||||
|
|||||||
88
ja/05.6.md
88
ja/05.6.md
@@ -9,10 +9,90 @@ redisはkey-valueを保存するシステムです。Memcachedに似ていて、
|
|||||||
現在redisが最もよく使われているのは新浪のマイクロブログプラットフォームでしょう。その次にFacebookに買収された画像フォーラムであるinstagramがあります。その他有名な[インターネット企業](http://redis.io/topics/whos-using-redis)もそうです。
|
現在redisが最もよく使われているのは新浪のマイクロブログプラットフォームでしょう。その次にFacebookに買収された画像フォーラムであるinstagramがあります。その他有名な[インターネット企業](http://redis.io/topics/whos-using-redis)もそうです。
|
||||||
|
|
||||||
Goは現在redisのドライバで以下をサポートしています
|
Goは現在redisのドライバで以下をサポートしています
|
||||||
- https://github.com/alphazero/Go-Redis
|
- [https://github.com/garyburd/redigo](https://github.com/garyburd/redigo)
|
||||||
- http://code.google.com/p/tideland-rdc/
|
- [https://github.com/go-redis/redis](https://github.com/go-redis/redis)
|
||||||
- https://github.com/simonz05/godis
|
- [https://github.com/hoisie/redis](https://github.com/hoisie/redis)
|
||||||
- https://github.com/hoisie/redis.go
|
- [https://github.com/alphazero/Go-Redis](https://github.com/alphazero/Go-Redis)
|
||||||
|
- [https://github.com/simonz05/godis](https://github.com/simonz05/godis)
|
||||||
|
|
||||||
|
Let's see how to use the driver that redigo to operate on a database:
|
||||||
|
|
||||||
|
```Go
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/garyburd/redigo/redis"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Pool *redis.Pool
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
redisHost := ":6379"
|
||||||
|
Pool = newPool(redisHost)
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPool(server string) *redis.Pool {
|
||||||
|
|
||||||
|
return &redis.Pool{
|
||||||
|
|
||||||
|
MaxIdle: 3,
|
||||||
|
IdleTimeout: 240 * time.Second,
|
||||||
|
|
||||||
|
Dial: func() (redis.Conn, error) {
|
||||||
|
c, err := redis.Dial("tcp", server)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c, err
|
||||||
|
},
|
||||||
|
|
||||||
|
TestOnBorrow: func(c redis.Conn, t time.Time) error {
|
||||||
|
_, err := c.Do("PING")
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func close() {
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt)
|
||||||
|
signal.Notify(c, syscall.SIGTERM)
|
||||||
|
signal.Notify(c, syscall.SIGKILL)
|
||||||
|
go func() {
|
||||||
|
<-c
|
||||||
|
Pool.Close()
|
||||||
|
os.Exit(0)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func Get(key string) ([]byte, error) {
|
||||||
|
|
||||||
|
conn := Pool.Get()
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
var data []byte
|
||||||
|
data, err := redis.Bytes(conn.Do("GET", key))
|
||||||
|
if err != nil {
|
||||||
|
return data, fmt.Errorf("error get key %s: %v", key, err)
|
||||||
|
}
|
||||||
|
return data, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
test, err := Get("test")
|
||||||
|
fmt.Println(test, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
現在私がforkした最新のドライバではいくつかのbugが修正されています。現在私自身の短縮ドメイン名サービスのプロジェクトの中で使用されています。(毎日200WぐらいのPV数があります。)
|
現在私がforkした最新のドライバではいくつかのbugが修正されています。現在私自身の短縮ドメイン名サービスのプロジェクトの中で使用されています。(毎日200WぐらいのPV数があります。)
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,90 @@ As the C language of the 21st century, Go has good support for NoSQL databases,
|
|||||||
redis is a key-value storage system like Memcached, that supports the string, list, set and zset(ordered set) value types.
|
redis is a key-value storage system like Memcached, that supports the string, list, set and zset(ordered set) value types.
|
||||||
|
|
||||||
There are some Go database drivers for redis:
|
There are some Go database drivers for redis:
|
||||||
|
- [https://github.com/garyburd/redigo](https://github.com/garyburd/redigo)
|
||||||
|
- [https://github.com/go-redis/redis](https://github.com/go-redis/redis)
|
||||||
|
- [https://github.com/hoisie/redis](https://github.com/hoisie/redis)
|
||||||
- [https://github.com/alphazero/Go-Redis](https://github.com/alphazero/Go-Redis)
|
- [https://github.com/alphazero/Go-Redis](https://github.com/alphazero/Go-Redis)
|
||||||
- [http://code.google.com/p/tideland-rdc/](http://code.google.com/p/tideland-rdc/)
|
|
||||||
- [https://github.com/simonz05/godis](https://github.com/simonz05/godis)
|
- [https://github.com/simonz05/godis](https://github.com/simonz05/godis)
|
||||||
- [https://github.com/hoisie/redis.go](https://github.com/hoisie/redis.go)
|
|
||||||
|
Let's see how to use the driver that redigo to operate on a database:
|
||||||
|
|
||||||
|
```Go
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/garyburd/redigo/redis"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Pool *redis.Pool
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
redisHost := ":6379"
|
||||||
|
Pool = newPool(redisHost)
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPool(server string) *redis.Pool {
|
||||||
|
|
||||||
|
return &redis.Pool{
|
||||||
|
|
||||||
|
MaxIdle: 3,
|
||||||
|
IdleTimeout: 240 * time.Second,
|
||||||
|
|
||||||
|
Dial: func() (redis.Conn, error) {
|
||||||
|
c, err := redis.Dial("tcp", server)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c, err
|
||||||
|
},
|
||||||
|
|
||||||
|
TestOnBorrow: func(c redis.Conn, t time.Time) error {
|
||||||
|
_, err := c.Do("PING")
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func close() {
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt)
|
||||||
|
signal.Notify(c, syscall.SIGTERM)
|
||||||
|
signal.Notify(c, syscall.SIGKILL)
|
||||||
|
go func() {
|
||||||
|
<-c
|
||||||
|
Pool.Close()
|
||||||
|
os.Exit(0)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func Get(key string) ([]byte, error) {
|
||||||
|
|
||||||
|
conn := Pool.Get()
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
var data []byte
|
||||||
|
data, err := redis.Bytes(conn.Do("GET", key))
|
||||||
|
if err != nil {
|
||||||
|
return data, fmt.Errorf("error get key %s: %v", key, err)
|
||||||
|
}
|
||||||
|
return data, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
test, err := Get("test")
|
||||||
|
fmt.Println(test, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
I forked the last of these packages, fixed some bugs, and used it in my short URL service (2 million PV every day).
|
I forked the last of these packages, fixed some bugs, and used it in my short URL service (2 million PV every day).
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user