Redis is a in-memory NoSQL database mainly used for caching. It's a key-value store which means each unique keys map to a value which could be either a stirng, list, set, hash, blob, JSON or any other data. Each keys are unique and can be queried.
To connect to a Redis cluster securely using the command line, you can use the redis-cli
tool with TLS and authentication:
Common redis operations across different data types:
Strings are the simplest Redis data type. A Redis string value can be up to 512 MB in size
Redis Lists are implemented as linked lists, optimized for fast insertions and deletions from both ends.
Hashes are maps between string fields and string values, ideal for representing objects.
Sets are unordered collections of unique strings. They support powerful set algebra operations.
Sorted Sets are similar to Sets but with an associated score that allows ordering.
Redis allows setting time-to-live (TTL) on keys and inspecting their status.
Use the INFO MEMORY
command to inspect memory consumption:
Redis provides a pub/sub mechanism to monitor events such as key updates, deletions, and expirations. To subscribe to all events under the myApp namespace:
You can automate monitoring of Redis keyspace events using Python and the redis
library. The following script connects to Redis, subscribes to a pattern, and logs events to both a file and the console: