Beispiel #1
0
func ExampleBool() {
	c, err := dial()
	if err != nil {
		panic(err)
	}
	defer c.Close()

	c.Do("SET", "foo", 1)
	exists, _ := redis.Bool(c.Do("EXISTS", "foo"))
	fmt.Printf("%#v\n", exists)
	// Output:
	// true
}
Beispiel #2
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
}