Redis is an open-source in-memory data structure store, used as a database, cache, and message broker. It supports various data structures such as strings, hashes, lists, sets, sorted sets, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of disk persistence, and provides high availability and automatic partitioning through Redis Sentinel and Redis Cluster.
Main Features of Redis
High Performance: Redis is an in-memory database with very fast read and write speeds.
Rich Data Types: Supports various data structures, suitable for different application scenarios.
Persistence: Supports data persistence to disk to prevent data loss.
Replication: Supports master-slave replication, allowing data to be replicated across multiple Redis instances.
High Availability: Provides monitoring, notifications, and automatic failover through Redis Sentinel.
Distributed: Provides automatic partitioning and high availability through Redis Cluster.
Transactions: Supports transactions, allowing multiple commands to be executed at once.
Application Scenarios of Redis
Cache: Redis can be used as a cache to improve data read and write speeds.
Counter: Redis's atomic operations can be used to implement counter functionality.
Message Queue: Redis's list structure can be used to implement a message queue.
Leaderboard: Redis's sorted sets can be used to implement leaderboard functionality.
Session Management: Redis can store session data to implement session management.
Distributed Lock: Redis's distributed lock can be used to implement concurrency control in distributed systems.
Redis Configuration
The Redis configuration file is located at /etc/redis/redis.conf, and Redis can be configured by modifying the configuration file.
Common configuration items are as follows:
daemonize: Whether to run as a daemon, default is no.
port: The port Redis server listens on, default is 6379.
bind: The address Redis server listens on, default is 0.0.0.0.
timeout: How long to close the connection after the client is idle, default is 0, meaning not to close.
loglevel: Log level, options are debug, verbose, notice, warning, default is notice.
logfile: Log file path, default is stdout.
databases: Number of databases, default is 16.
save: Persistence configuration, format is save
rdbcompression: Whether to compress rdb files, default is yes.
dbfilename: rdb file name, default is dump.rdb.
dir: rdb file save path, default is /var/lib/redis.
maxmemory: Maximum memory limit, default is 0, meaning no limit.
maxmemory-policy: Policy for handling memory over the limit, options are volatile-lru, allkeys-lru, volatile-random, allkeys-random, volatile-ttl, default is noeviction.
appendonly: Whether to enable aof persistence, default is no.
appendfilename: aof file name, default is appendonly.aof.
appendfsync: aof persistence policy, options are always, everysec, no, default is everysec.
requirepass: Set password, default is not set.
maxclients: Maximum number of client connections, default is 10000.
maxmemory-samples: Number of samples for LRU algorithm, default is 5.
slaveof: Master-slave replication configuration, format is slaveof
masterauth: Master-slave replication password.
cluster-enabled: Whether to enable cluster mode, default is no.
cluster-config-file: Cluster configuration file, default is nodes.conf.
cluster-node-timeout: Cluster node timeout, default is 15000.
cluster-slave-validity-factor: Cluster slave validity factor, default is 10.
cluster-migration-barrier: Cluster migration barrier, default is 1.
cluster-require-full-coverage: Whether the cluster requires all slots to be covered, default is yes.
cluster-replica-no-failover: Whether the cluster slave nodes can perform failover, default is no.
cluster-announce-ip: Cluster node broadcast address.
cluster-announce-port: Cluster node broadcast port.
cluster-announce-bus-port: Cluster node bus port.