Sobes.tech
Junior — Middle

Can you explain how Redis database works and is organized?

sobes.tech AI

Answer from AI

Redis is a high-performance key-value database that stores data in memory for fast access. It is often used as a cache, message broker, or for session storage.

Main features of Redis:

  • In-memory data storage with optional periodic disk persistence.
  • Support for various data structures: strings, lists, sets, hashes, sorted sets, and more.
  • Support for atomic operations and transactions.
  • Ability to configure replication and clustering for scalability and fault tolerance.

Example of using Redis in Python with the redis-py library:

import redis

r = redis.Redis(host='localhost', port=6379, db=0)

# Set a value
r.set('key', 'value')

# Get a value
value = r.get('key')
print(value.decode('utf-8'))