Exemplo n.º 1
0
func WriteResult(result string) {
	c := pool.Get()
	defer c.Close()

	_, err := redis.String(c.Do("LPUSH", "results", result))
	if err != nil {
		// never mind
	}

	return
}
Exemplo n.º 2
0
func ExampleString() {
	c, err := dial()
	if err != nil {
		panic(err)
	}
	defer c.Close()

	c.Do("SET", "hello", "world")
	s, err := redis.String(c.Do("GET", "hello"))
	fmt.Printf("%#v\n", s)
	// Output:
	// "world"
}
Exemplo n.º 3
0
func AcquireSchedulerLock(interval, timeout int) bool {
	c := pool.Get()
	defer c.Close()

	exists, err := redis.Bool(c.Do("EXISTS", "scheduler:last_run"))
	if err != nil || exists {
		return false
	}

	_, err = redis.String(c.Do("SET", "scheduler:lock", "LOCK", "NX", "EX", timeout))
	if err != nil {
		return false
	}

	c.Do("SET", "scheduler:last_run", time.Now().Format(time.RFC3339), "EX", interval)

	return true
}
Exemplo n.º 4
0
// This example implements ZPOP as described at
// http://redis.io/topics/transactions using WATCH/MULTI/EXEC and scripting.
func Example_zpop() {
	c, err := dial()
	if err != nil {
		fmt.Println(err)
		return
	}
	defer c.Close()

	// Add test data using a pipeline.

	for i, member := range []string{"red", "blue", "green"} {
		c.Send("ZADD", "zset", i, member)
	}
	if _, err := c.Do(""); err != nil {
		fmt.Println(err)
		return
	}

	// Pop using WATCH/MULTI/EXEC

	v, err := zpop(c, "zset")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(v)

	// Pop using a script.

	v, err = redis.String(zpopScript.Do(c, "zset"))
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(v)

	// Output:
	// red
	// blue
}