directory search
Cluster cluster addslots(集群 槽位) cluster count failure reports(集群计数失败报告) cluster countkeysinslot cluster delslots cluster failover cluster forget cluster getkeysinslot cluster info cluster keyslot(集群键槽) cluster meet cluster nodes(集群节点) cluster replicate(集群复制) cluster reset(集群重置) cluster saveconfig cluster set config epoch cluster setslot cluster slaves cluster slots readonly readwrite Connection auth echo ping quit select swapdb Geo geoadd geodist geohash geopos georadius georadiusbymember Hashes hdel hexists hget hgetall hincrby hincrbyfloat hkeys hlen hmget hmset hscan hset hsetnx hstrlen hvals HyperLogLog pfadd pfcount pfmerge Keys del dump exists expire expireat keys migrate move object persist pexpire pexpireat pttl randomkey rename renamenx restore scan sort touch ttl type unlink wait Lists blpop brpop brpoplpush lindex linsert llen lpop lpush lpushx lrange lrem lset ltrim rpop rpoplpush rpush rpushx Pub/Sub psubscribe publish pubsub punsubscribe subscribe unsubscribe Scripting eval evalsha script debug script exists script flush script kill script load Server bgrewriteaof bgsave client getname client kill client list client pause client reply client setname command command count command getkeys command info config get config resetstat config rewrite config set dbsize debug object debug segfault flushall flushdb info lastsave monitor role save shutdown slaveof slowlog time Sets sadd scard sdiff sdiffstore sinter sinterstore sismember smembers smove spop srandmember srem sscan sunion sunionstore Sorted Sets zadd zcard zcount zincrby zinterstore zlexcount zrange zrangebylex zrangebyscore zrank zrem zremrangebylex zremrangebyrank zremrangebyscore zrevrange zrevrangebylex zrevrangebyscore zrevrank zscan zscore zunionstore Strings append bitcount bitfield bitop bitpos decr decrby get getbit getrange getset incr incrby incrbyfloat mget mset msetnx psetex set setbit setex setnx setrange strlen Transactions discard exec multi unwatch watch
characters

SETBIT key offset value

自2.2.0起可用。

时间复杂度: O(1)

设置或清除存储在的字符串值中偏移量的位。

该位根据设置或清零,可以是0或1.当不存在时,将创建一个新的字符串值。该字符串的增长,以确保它可以保持一点偏移量。所述偏移参数是必需的,以大于或等于0,且小于232(这个限制位图512MB)。当密钥字符串增长时,添加的位设置为0。

警告:当设置最后一个可能的位(偏移量等于232 -1)并且存储在上的字符串值尚未包含字符串值或保存一个小字符串值时,Redis需要分配所有可阻塞服务器的中间存储器一段时间。在2010年的MacBook Pro上,设置232-1位(分配512MB)需要约300ms,设置位编号230-1(128MB分配)需要约80ms,设置位编号228-1(32MB分配)需要约30ms,设置位数字226 -1(8MB分配)需要〜8ms。请注意,一旦完成第一次分配,对同一个密钥的 SETBIT后续调用将不会产生分配开销。

返回值

整数回复:存储在偏移处的原始位值。

例子

redis>  SETBIT mykey 7 1 (integer) 0 redis>  SETBIT mykey 7 0 (integer) 1 redis>  GET mykey "\u0000"

Previous article: Next article: