Redis Cheat Sheet
Redis Cheat Sheet

Redis Cheat Sheet

Commands for Strings

1. SET key value: Stores a value for a key.

2. GET key: Retrieves the stored value of a key.

3. DEL key: Deletes a key and its value.

4. INCR key: Increases the numerical value of a key by one.

5. DECR key: Decreases the numerical value of a key by one.

6. APPEND key value: Appends a value to the end of the existing value of a key.

7. MSET key1 value1 key2 value2 ...: Sets multiple keys with their corresponding values.

8. MGET key1 key2 ...: Retrieves the values of multiple keys.


Commands for Lists

1. LPUSH key value: Adds a value to the beginning of the list.

2. RPUSH key value: Adds a value to the end of the list.

3. LPOP key: Removes and returns the first element of the list.

4. RPOP key: Removes and returns the last element of the list.

5. LLEN key: Gets the length of the list.

6. LRANGE key start stop: Retrieves a range of elements from the list.

7. LREM key count value: Removes elements equal to the value from the list.


Commands for Sets

1. SADD key member1 member2 ...: Adds one or more members to the set.

2. SREM key member: Removes a member from the set.

3. SMEMBERS key: Retrieves all members of the set.

4. SISMEMBER key member: Checks if a member exists in the set.

5. SCARD key: Gets the number of members in the set.

6. SUNION key1 key2 ...: Gets the union of multiple sets.

7. SINTER key1 key2 ...: Gets the intersection of multiple sets.


Commands for Sorted Sets

1. ZADD key score1 member1 score2 member2 ...: Adds one or more members with their scores.

2. ZREM key member: Removes a member from the sorted set.

3. ZRANGE key start stop [WITHSCORES]: Retrieves members in a range.

4. ZREVRANGE key start stop [WITHSCORES]: Retrieves members in a reverse range.

5. ZRANK key member: Gets a member's rank.

6. ZINCRBY key increment member: Increases the score of a member by a specified amount.

7. ZCARD key: Gets the number of members in the sorted set.


Commands for Hashes

1. HSET key field value: Sets a field-value pair in a hash.

2. HGET key field: Retrieves the value of a specific field in a hash.

3. HDEL key field: Deletes a field-value pair from a hash.

4. HGETALL key: Retrieves all field-value pairs in a hash.

5. HEXISTS key field: Checks if a field exists in a hash.

6. HLEN key: Gets the number of field-value pairs in a hash.

7. HINCRBY key field increment: Increases the numerical value of a specific field in a hash.


Commands for Bitmaps

1. SETBIT key offset value: Sets a bit at a specified position.

2. GETBIT key offset: Gets the value of a bit at a specified position.

3. BITCOUNT key [start end]: Counts the number of set bits (1s) in a key.

4. BITOP operation destkey key1 key2 ...: Performs bitwise operations (AND, OR, XOR, NOT) on bitmaps.


Commands for HyperLogLog

1. PFADD key element1 element2 ...: Adds one or more elements to the HyperLogLog.

2. PFCOUNT key1 key2 ...: Estimates the number of unique elements in one or more HyperLogLogs.

3. PFMERGE destkey sourcekey1 sourcekey2 ...: Merges multiple HyperLogLogs into one.


Commands for Bitfields

1. BITFIELD key [GET type offset] [SET type offset value] [INCRBY type offset increment]: Performs various bitfield operations on a key.


Commands for Geospatial Indexes

1. GEOADD key longitude latitude member ...: Adds geospatial items (longitude, latitude, member).

2. GEOPOS key member ...: Retrieves the coordinates of members.

3. GEODIST key member1 member2 [unit]: Calculates the distance between two members.

4. GEORADIUS key longitude latitude radius [unit] [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC]: Searches for members within a radius from a point.

5. GEORADIUSBYMEMBER key member radius [unit] [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC]: Searches for members within a radius from a specified member.


Commands for Streams

1. XADD key field value [field value ...]: Adds an entry to a stream.

2. XREAD [COUNT count] [BLOCK milliseconds] STREAMS key [key ...] ID [ID ...]: Reads data from streams.

3. XGROUP CREATE key groupname id-or-$: Creates a consumer group for a stream.

4. XREADGROUP GROUP groupname consumer [COUNT count] [BLOCK milliseconds] STREAMS key [key ...] ID [ID ...]: Reads data from streams as a consumer group.

5. XACK key groupname ID [ID ...]: Acknowledges receipt of stream entries by a consumer group.

6. XLEN key: Gets the number of entries in a stream.

7. XRANGE key start end [COUNT count]: Retrieves a range of entries from a stream.

要查看或添加评论,请登录

Mohammad Dastpak的更多文章

社区洞察

其他会员也浏览了