示例#1
0
func InitRedis() {
	//
	cs = new(data.DB)
	cs.Init()

	redis_cs = godis.New("tcp:localhost:6379", 0, "")
	//cs.Flushdb()
}
示例#2
0
func daemon(m <-chan Message, ex chan<- bool) {
	c := godis.New("tcp:127.0.0.1:6379", 0, "")
	c.Flushdb()
	for {
		select {
		case mm, ok := <-m:
			if !ok {
				fmt.Printf("Read from channel failed")
			}
			c.Rpush(mm.name, mm.value)
		case <-time.After(0.1e9):
			ex <- true
		}
	}
	fmt.Printf("END DAEMON \n")
}
示例#3
0
文件: string.go 项目: Tonylinxm/godis
func main() {
	// new client on default port 6379, select db 0 and use no password
	c := godis.New("", 0, "")

	// set the key "foo" to "Hello Redis"
	if err := c.Set("foo", "Hello Redis"); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	// retrieve the value of "foo". Returns an Elem obj
	elem, _ := c.Get("foo")

	// convert the obj to a string and print it
	fmt.Println("foo:", elem.String())
}
示例#4
0
// DbConnect returns a connection to the Redis database. Connection details can
// be provided through the CITEPLASM_REDIS_ADDR, CITEPLASM_REDIS_DB, and
// CITEPLASM_REDIS_PWD environment variables.
func DbConnect() *godis.Client {
	addr := os.Getenv("CITEPLASM_REDIS_ADDR")
	db := os.Getenv("CITEPLASM_REDIS_DB")
	pw := os.Getenv("CITEPLASM_REDIS_PWD")

	// default db if not provided
	if db == "" {
		db = "0"
	}

	// conver the DB to an integer value, error out if not possible
	dbi, err := strconv.Atoi(db)
	if err != nil {
		log.Fatal("Environment variable CITEPLASM_REDIS_DB must be an integer.")
	}

	return godis.New(addr, dbi, pw)
}
示例#5
0
// Establish a redis connection, return the godis.Client
func redisConn(s string) (c *godis.Client, err os.Error) {
	u, err := url.Parse(s)
	if err != nil {
		return nil, err
	}

	// url.Parse doesn't return ports, so split on ':'
	hostPort := strings.Split(u.Host, ":")

	// Create a slice with our strings
	cs := []string{"tcp", hostPort[0], hostPort[1]}

	// Result: 'tcp:Host:Port'
	connString := strings.Join(cs, ":")

	// Return a godis client
	c = godis.New(connString, 0, u.RawUserinfo)
	return c, nil
}
示例#6
0
文件: list.go 项目: patrickxb/godis
func main() {
	// new client on default port 6379, select db 0 and use no password.
	c := godis.New("", 0, "")

	// values we want to store
	values := []int{0, 1, 1, 2, 3, 5, 8, 13, 21, 34}

	// push the values to the redis list
	for _, v := range values {
		if _, err := c.Rpush("bar", v); err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}
	}

	// retrieve the items in the list. Returns a Reply object.
	res, _ := c.Lrange("bar", 0, 9)

	// convert the list to an array of ints and print it.
	fmt.Println("bar:", res.IntArray())
}
示例#7
0
文件: kurz.go 项目: vormplus/kurz.go
// bootstraps the server
func bootstrap(path string) os.Error {
	config = NewConfig(path)
	config.Parse()

	host := config.GetStringDefault("redis.address", "tcp:localhost:6379")
	db := config.GetIntDefault("redis.database", 0)
	passwd := config.GetStringDefault("redis.password", "")

	redis = godis.New(host, db, passwd)

	web.Config.StaticDir = config.GetStringDefault("static-directory", "")

	web.Post("/shorten/(.*)", shorten)
	// support for Get makes it easier to implement a bookmarklet
	web.Get("/shorten/(.*)", shorten)

	web.Get("/", index)
	web.Get("/([a-zA-Z0-9]*)", resolve)
	web.Get("/([a-zA-Z0-9]*)\\+", info)
	web.Get("/latest/([0-9]*)", latest)
	web.Get("/info/([a-zA-Z0-9]*)", info)

	return nil
}
示例#8
0
文件: registry.go 项目: emk/cstore
// Create a new Registry client.
func NewRegistry() *Registry {
	return &Registry{client: godis.New("", 0, ""), quit: make(chan bool)}
}