0% found this document useful (0 votes)
278 views6 pages

Time Complexity Cheat Sheet

This document provides a cheat sheet summarizing the time complexity of Redis commands grouped by type. It lists over 100 Redis commands and their time complexity, which ranges from O(1) for many single-item commands up to O(N*M) for commands operating on multiple keys or elements where N is the number of keys and M is the number of elements. Many cluster, pubsub, and scripting commands are O(N) where N is the number of clients or nodes.

Uploaded by

Diogenes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
278 views6 pages

Time Complexity Cheat Sheet

This document provides a cheat sheet summarizing the time complexity of Redis commands grouped by type. It lists over 100 Redis commands and their time complexity, which ranges from O(1) for many single-item commands up to O(N*M) for commands operating on multiple keys or elements where N is the number of keys and M is the number of elements. Many cluster, pubsub, and scripting commands are O(N) where N is the number of clients or nodes.

Uploaded by

Diogenes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Redis commands time complexity cheat sheet

Grouped by command type and ordered by time complexity.

Regular
Group Command Time Complexity
cluster cluster keyslot O(N)
cluster cluster reset O(N)
cluster cluster delslots O(N)
cluster cluster nodes O(N)
cluster cluster count-failure-reports O(N)
cluster cluster addslots O(N)
cluster cluster slots O(N)
cluster cluster getkeysinslot O(log(N))
cluster cluster meet O(1)
cluster cluster failover O(1)
cluster cluster forget O(1)
cluster cluster countkeysinslot O(1)
cluster cluster info O(1)
cluster cluster saveconfig O(1)
cluster cluster replicate O(1)
cluster readonly O(1)
cluster readwrite O(1)
cluster cluster replicas O(1)
cluster cluster slaves O(1)
cluster cluster set-config-epoch O(1)
cluster cluster setslot O(1)
connection swapdb -
connection select-
connection quit -
connection ping -
connection echo -
connection auth -
generic sort O(N+M*log(M))
generic touch O(N)
generic migrate O(N)
generic keys O(N)
generic del O(N)
generic scan O(1)
generic wait O(1)
generic unlink O(1)
generic type O(1)
generic ttl O(1)
generic restore O(1)
generic rename O(1)
generic renamenx O(1)
generic pttl O(1)
generic persist O(1)
generic pexpireat O(1)
generic move O(1)
generic object O(1)
generic pexpire O(1)
generic randomkey O(1)
generic expireat O(1)
generic existsO(1)
generic dump O(1)
generic expire O(1)
geo georadiusbymember O(N+log(M))
geo georadius O(N+log(M))
geo geodist O(log(N))
geo geohash O(log(N))
geo geopos O(log(N))
geo geoadd O(log(N))
hash hvals O(N)
hash hmset O(N)
hash hgetall O(N)
hash hkeysO(N)
hash hmget O(N)
hash hdel O(N)
hash hscanO(1)
hash hstrlen O(1)
hash hsetnx O(1)
hash hlen O(1)
hash hexists O(1)
hash hincrby O(1)
hash hget O(1)
hash hincrbyfloat O(1)
hash hset O(1)
hyperloglog pfmerge O(N)
hyperloglog pfcount O(1)
hyperloglog pfadd O(1)
list lrange O(S+N)
list ltrim O(N)
list lset O(N)
list linsert O(N)
list lindex O(N)
list lrem O(N)
list rpushx O(1)
list rpushO(1)
list rpop O(1)
list rpoplpush O(1)
list lpushx O(1)
list lpush O(1)
list lpop O(1)
list llen O(1)
list brpoplpush O(1)
list brpop O(1)
list blpop O(1)
pubsub punsubscribe O(N+M)
pubsub publish O(N+M)
pubsub unsubscribe O(N)
pubsub subscribe O(N)
pubsub pubsub O(N)
pubsub psubscribe O(N)
scripting script exists O(N)
scripting script flush O(N)
scripting script load O(N)
scripting script debug O(1)
scripting script kill O(1)
scripting evalsha Depends on the script that is executed
scripting eval Depends on the script that is executed
server memory usage O(N)
server command getkeys O(N)
server command info O(N)
server command O(N)
server client list O(N)
server client kill O(N)
server client unblock O(log N)
server time O(1)
server config resetstat O(1)
server command count O(1)
server client pause O(1)
server client getname O(1)
server client setname O(1)
server client reply O(1)
server client id O(1)
server sync -
server slaveof -
server replicaof -
server shutdown -
server slowlog -
server save -
server role -
server memory stats -
server monitor -
server memory purge -
server memory malloc-stats -
server lastsave -
server memory doctor -
server memory help -
server flushdb -
server flushall -
server debug segfault -
server debug object -
server dbsize -
server config set -
server config rewrite -
server config get -
server bgsave -
server bgrewriteaof -
server info -
set sinterstore O(N*M)
set sinterO(N*M)
set sunion O(N)
set sunionstoreO(N)
set srem O(N)
set smembers O(N)
set sdiff O(N)
set sdiffstore O(N)
set sscan O(1)
set spop O(1)
set sismember O(1)
set srandmember O(1)
set sadd O(1)
set scard O(1)
set smove O(1)
sorted_set zinterstore O(N*K)
sorted_set zunionstoreO(N)
sorted_set zrem O(M*log(N))
sorted_set zrevrange O(log(N)+M)
sorted_set zremrangebyrank O(log(N)+M)
sorted_set zremrangebyscore O(log(N)+M)
sorted_set zrevrangebylex O(log(N)+M)
sorted_set zrangebyscore O(log(N)+M)
sorted_set zremrangebylex O(log(N)+M)
sorted_set zrevrangebyscore O(log(N)+M)
sorted_set zrangebylex O(log(N)+M)
sorted_set zrange O(log(N)+M)
sorted_set zpopmin O(log(N)*M)
sorted_set zpopmax O(log(N)*M)
sorted_set zrevrank O(log(N))
sorted_set zrank O(log(N))
sorted_set zlexcount O(log(N))
sorted_set zincrby O(log(N))
sorted_set zadd O(log(N))
sorted_set zcount O(log(N))
sorted_set bzpopmax O(log(N))
sorted_set bzpopmin O(log(N))
sorted_set zscan O(1)
sorted_set zscore O(1)
sorted_set zcard O(1)
stream xpending O(N)
stream xread O(N)
stream xrange O(N)
stream xtrim O(N)
stream xrevrange O(N)
stream xinfo O(N)
stream xreadgroup O(M)
stream xclaim O(log N)
stream xack O(1)
stream xlen O(1)
stream xadd O(1)
stream xdel O(1)
stream xgroup O(1)
stringmsetnx O(N)
stringmget O(N)
stringmset O(N)
stringgetrange O(N)
stringbitpos O(N)
stringbitop O(N)
stringbitcount O(N)
stringappend O(1)
stringstrlenO(1)
stringsetex O(1)
stringsetrange O(1)
stringsetnx O(1)
stringsetbit O(1)
stringpsetex O(1)
stringincrby O(1)
stringincrbyfloat O(1)
stringincr O(1)
stringgetbitO(1)
stringget O(1)
stringgetset O(1)
stringset O(1)
stringdecrby O(1)
stringdecr O(1)
stringbitfield O(1)
transactions watch O(1)
transactions unwatch O(1)
transactions multi -
transactions exec -
transactions discard -

You might also like