[go: up one dir, main page]

0% found this document useful (0 votes)
85 views4 pages

Redis Cheat Sheet

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)
85 views4 pages

Redis Cheat Sheet

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
You are on page 1/ 4

Redis Cheat-sheet

1. Basics

1.1. Start Redis Server

redis-server

1.2. Connect to Redis Server

redis-cli

2. Data Types

2.1. Strings

# Set a key with a value


SET key value

# Get the value of a key


GET key

2.2. Lists

# Add element to the beginning of a list


LPUSH key value

# Add element to the end of a list


RPUSH key value

# Get range of elements in a list


LRANGE key start stop

2.3. Sets

# Add member to a set


SADD key member

# Get all members of a set


SMEMBERS key

2.4. Hashes

# Set field in hash


HSET key field value

# Get value of a field in hash


HGET key field

2.5. Sorted Sets

# Add member to a sorted set with a score


ZADD key score member

# Get range of elements in a sorted set by score


ZRANGEBYSCORE key min max
3. Expiry

3.1. Set Expiry for a Key

# Set expiry in seconds


EXPIRE key seconds

4. Pub/Sub (Publish/Subscribe)

4.1. Subscribe to a Channel

SUBSCRIBE channel

4.2. Publish to a Channel

PUBLISH channel message

5. Transactions

5.1. Begin Transaction

MULTI

5.2. Execute Transaction

EXEC

6. Configuration

6.1. Get Configuration

CONFIG GET parameter

6.2. Set Configuration

CONFIG SET parameter value

7. Server

7.1. Get Server Information

INFO

7.2. Monitor Commands

MONITOR

8. Remote Server Operations

8.1. Connect to Remote Server

redis-cli -h hostname -p port -a password


9. Additional Commands and Concepts

9.1. Key Patterns and Wildcards

# Find keys matching a pattern


KEYS pattern

# Use SCAN for iterating over keys


SCAN cursor [MATCH pattern] [COUNT count]

9.2. Bitwise Operations

# Bitwise AND, OR, XOR, etc.


BITOP operation destkey key [key ...]

9.3. Key Manipulation

# Rename a key
RENAME key new_key

9.4. Scripting

# Execute a Lua script


EVAL script numkeys key [key ...] arg [arg ...]

9.5. Replication

# Set up a slave
SLAVEOF master_ip master_port

9.6. Partitioning (Redis Cluster)

# Set up a Redis Cluster


CLUSTER [subcommand]

9.7. Memory Usage

# Memory usage of a key


MEMORY USAGE key

# Memory usage of the entire database


INFO MEMORY

9.8. Data Backups

# Create a backup (snapshot)


SAVE

# Restore a backup
BGSAVE

9.9. Security

# Set a password
CONFIG SET requirepass password
9.10. Monitoring

# Monitor Redis commands in real-time


MONITOR

9.11. Persistence

# AOF (Append-Only File) persistence


CONFIG SET appendonly yes

9.12. GeoSpatial Indexing

# Add geospatial data


GEOADD key longitude latitude member

Here is a quick reference Redis cheat sheet compiled by @code.clash. It provides examples of Redis commands for easy reference. For more in-depth
information and advanced usage, be sure to check out the official Redis documentation.

Happy coding!

You might also like