Giter VIP home page Giter VIP logo

goredis-1's Introduction

goredis

NOTE: This is a modified version of redis.go by hoise to support the latest version of go.

NOTE: This project was called redis.go and renamed to goredis because of this. (In short, we can no longer use package names end in .go.)

This package supports the latest release of Go.

goredis is a client for the redis key-value store.

Some features include:

  • Designed for Redis 1.3.x.
  • Support for all redis types - strings, lists, sets, sorted sets, and hashes
  • Very simple usage
  • Connection pooling ( with configurable size )
  • Support for concurrent access
  • Manages connections to the redis server, including dropped and timed out connections
  • Marshaling/Unmarshaling go types to hashes

This library is stable and is used in production environments. However, some commands have not been tested as thoroughly as others. If you find any bugs please file an issue!

Install

go get github.com/monnand/goredis

Examples

Most of the examples connect to a redis database running in the default port -- 6367.

Instantiating the client

//connects to the default port (6379)
var client goredis.Client 
 
//connects to port 8379, database 13
var client2 goredis.Client
client2.Addr = "127.0.0.1:8379"
client2.Db = 13

Strings

var client goredis.Client
client.Set("a", []byte("hello"))
val, _ := client.Get("a")
println(string(val))
client.Del("a")

Lists

var client goredis.Client
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")

Publish/Subscribe

sub := make(chan string, 1)
sub <- "foo"
messages := make(chan Message, 0)
go client.Subscribe(sub, nil, nil, nil, messages)

time.Sleep(10 * 1000 * 1000)
client.Publish("foo", []byte("bar"))

msg := <-messages
println("received from:", msg.Channel, " message:", string(msg.Message))

close(sub)
close(messages)

More examples coming soon. See redis_test.go for more usage examples.

(Known) Projects using this package

Commands not supported yet

  • MULTI/EXEC/DISCARD/WATCH/UNWATCH
  • SORT
  • ZUNIONSTORE / ZINTERSTORE

goredis-1's People

Contributors

monnand avatar hoisie avatar astaxie avatar cthom06 avatar liufuqiang avatar etherealmachine avatar guncha avatar saschpe avatar yohcop avatar redoufu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.