mirror of
				https://bitbucket.org/s_l_teichmann/mtsatellite
				synced 2025-10-31 08:05:27 +01:00 
			
		
		
		
	Simplified Redis code a bit when writing booleans to client.
This commit is contained in:
		| @@ -19,6 +19,8 @@ var ( | ||||
| 	redisCrnl        = []byte("\r\n") | ||||
| 	redisEmptyArray  = []byte("*0\r\n") | ||||
| 	redisQueued      = []byte("+QUEUED\r\n") | ||||
| 	redisTrue        = []byte(":1\r\n") | ||||
| 	redisFalse       = []byte(":0\r\n") | ||||
| ) | ||||
|  | ||||
| type Connection struct { | ||||
| @@ -188,15 +190,14 @@ func (c *Connection) writeEmptyArray() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| func asInt(b bool) int { | ||||
| 	if b { | ||||
| 		return 1 | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func (c *Connection) writeBool(b bool) bool { | ||||
| 	if _, err := c.conn.Write([]byte(fmt.Sprintf(":%d\r\n", asInt(b)))); err != nil { | ||||
| 	var err error | ||||
| 	if b { | ||||
| 		_, err = c.conn.Write(redisTrue) | ||||
| 	} else { | ||||
| 		_, err = c.conn.Write(redisFalse) | ||||
| 	} | ||||
| 	if err != nil { | ||||
| 		logError(err) | ||||
| 		return false | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user