Redis etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Redis etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

25 Eylül 2026 Cuma

Redis - Bitset Veri Yapısı

Giriş
Komutlar şöyle
SETBIT
GETBIT
BITCOUNT
BITOP
BITPOS

SETBIT
Bir kullanıcının yılın hangi gününde giriş yapıtğını atamak için şöyle yaparız
SETBIT sign:123 10 1

Burada sign:123 key yani kullanıcı adı, 10 ise bitoffset ve bit değeri 1

GETBIT
Okumak için şöyle yaparız
GETBIT sign:123 10

BITCOUNT
Bu kullanıcı yılın kaç günü giriş yapmış görmek için şöyle yaparız
Okumak için şöyle yaparız

BITOP
İki tane kullanıcının bitsetlerini karşılaştırmak için şöyle yaparız
BITOP AND result sign:d123 sign:124

sonra şöyle yaparız
BITCOUNT result

13 Eylül 2023 Çarşamba

Redis Hash Veri Yapısı

Giriş
Açıklaması şöyle
Redis Hashes offer built-in functionality for sorting and searching data, making it easy to find specific data points or organize data based on certain criteria.

Redis Hashes offers transaction support, allowing you to perform multiple operations on data in a single transaction, ensuring consistency and reducing the risk of data corruption.

Redis Hashes are highly reliable, with built-in data replication and backup features to ensure that your data is always available and recoverable in the event of a failure.

Redis Hashes offer built-in security features, including support for SSL/TLS encryption and password authentication, making it a secure solution for applications that handle sensitive data.
1. HSET
Açıklaması şöyle
The HSET command sets the value of a field in a hash. If the field does not exist, it creates a new field and sets its value. If the field already exists, it overwrites its value.
Örnek
Şöyle yaparız. This command sets the name of user1 to “John”.      
HSET user1 name "John"
2. HGET
Açıklaması şöyle
The HGET command gets the value of a field in a hash. If the field exists, it returns its value. If the field does not exist, it returns nil.
Örnek
Şöyle yaparız. This command gets the name of user1.
HGET user1 name
3. HMSET
Açıklaması şöyle
The HMSET command sets multiple fields in a hash.
Örnek
Şöyle yaparız. This command sets the name, email, and age of user1.
HMSET user1 name "John" email "john@example.com" age 30
4. HMGET
Açıklaması şöyle
The HMGET command gets the values of multiple fields in a hash.
Örnek
Şöyle yaparız. This command gets the name, email, and age of user1.
HMGET user1 name email age
5. HDEL
Açıklaması şöyle
The HDEL command deletes one or more fields in a hash.
Örnek
Şöyle yaparız. This command deletes the age field of user1.
HDEL user1 age
6. HEXISTS
Açıklaması şöyle
The HEXISTS command checks if a field exists in a hash.
Örnek
Şöyle yaparız. This command checks if the name field exists in user1.
HEXISTS user1 name
7. HKEYS
Açıklaması şöyle
The HKEYS command gets all the keys in a hash.
Örnek
Şöyle yaparız. This command gets all the keys in user1.
HKEYS user1
8. HVALS
Açıklaması şöyle
The HVALS command gets all the values in a hash.
Örnek
Şöyle yaparız. This command gets all the values in user1.
HVALS user1
9. HLEN
Açıklaması şöyle
The HLEN command gets the number of fields in a hash.
Örnek
Şöyle yaparız. This command gets the number of fields in user1.
HLEN user1
10. HINCRBY
Açıklaması şöyle
The HINCRBY command increments the value of a field in a hash by a specified amount.
Örnek
Şöyle yaparız. This command increments the age of the user1 by 5.
HINCRBY user1 age 5
11. HINCRBYFLOAT
Açıklaması şöyle
This command increments the value of a floating-point field in a hash by a specified amount.
Örnek
Şöyle yaparız. This command increments the weight of user1 by 2.5
HINCRBYFLOAT user1 weight 2.5
Örnek
Şöyle yaparız
// create a Redis Hash named “customer1” using the HMSET
HMSET customer1 name "John Doe" email "johndoe@example.com" address "123 Main St"
  phone "555-1234" orders "5"

// use the HGET command to get the name and email of the customer
HGET customer1 name
//Output: “John Doe”

HGET customer1 email
// Output: “johndoe@example.com”

// use the HSET command to update the phone number of the customer
HSET customer1 phone "555-5678"

// use the HINCRBY command to increment the order count for the customer
HINCRBY customer1 orders 1

// se the HMGET command to get the customer’s address and order history
HMGET customer1 address orders
// Output: [“123 Main St”, “6”] 

// use the HDEL command to delete the customer’s phone number
HDEL customer1 phone

// use the HEXISTS command to check if a field exists in the customer1 hash
HEXISTS customer1 email
// Output: 1 (true)

HEXISTS customer1 phone
// Output: 0 (false)



6 Mart 2023 Pazartesi

Redis - Key-Value Veri Yapısı

SET
Şöyle yaparız
SET lock_name arbitrary_lock_value NX EX 10 # acquire the lock
# ... do something to the shared resource DEL lock_name # release the lock
SET NX
Atomic olarak çalışır. Eski hali SETNX. Sonradan SET komutuna NX parametresi haline geldi. Açıklaması şöyle
Because Redis has atomic writes, we can use a SET NX operation to only set the key if it’s not there. This means that Redis guarantees that only one worker will the race for a particular key. The official documentation says that the Redlock algorithm is preferred over SET NX because it “but offers better guarantees and is fault tolerant.” We are not looking to use a lock with Redis, however, just a one-way gate that prevents multiple execution. As long as Redis can prevent the race condition where two workers read the same value for the gate and both pass through it, that is all we need.
Örnek
Şöyle yaparız
SETNX lock_name true

DEL lock_name
EXPIRE
Örnek
Şöyle yaparız
SETNX lock_name arbitrary_lock_value
EXPIRE lock_name 10

30 Ocak 2023 Pazartesi

Docker Compose ve Redis Sentinel Mode

Örnek
Şöyle yaparız. Burada bir redis master ve bir redis sentinel var
version: '2'

networks:
  app-tier:
    driver: bridge

services:
  redis:
    image: 'bitnami/redis:latest'
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
    ports:
      - '6379:6379'
    networks:
      - app-tier
  redis-sentinel:
    image: 'bitnami/redis-sentinel:latest'
    environment:
      - REDIS_MASTER_HOST=localhost
      - REDIS_SENTINEL_RESOLVE_HOSTNAMES=yes
    ports:
      - '26379:26379'
    networks:
      - app-tier
Örnek
Şöyle yaparız. REDIS_MASTER_SET ile sentinelin hangi set için çalıştığı belirtilir
version: '3.8'
services:
  redis-master:
    container_name: redis-master
    image: 'bitnami/redis:latest'
    environment:
      - REDIS_REPLICATION_MODE=master
      - REDIS_PASSWORD=redispassword
    ports:
      - "6379:6379"
  redis-slave:
    container_name: slave-redis
    image: 'bitnami/redis:latest'
    environment:
      - REDIS_REPLICATION_MODE=slave
      - REDIS_MASTER_HOST=redis-master
      - REDIS_MASTER_PASSWORD=redispassword
      - REDIS_PASSWORD=redispassword
    ports:
      - "7000:6379"
    depends_on:
      - redis-master
  redis-sentinel-1:
    image: 'bitnami/redis-sentinel:latest'
    container_name: sentinel-1
    environment:
      - REDIS_MASTER_SET=mymaster
      - REDIS_MASTER_HOST=127.0.0.1
      - REDIS_MASTER_PASSWORD=redispassword
      - REDIS_SENTINEL_DOWN_AFTER_MILLISECONDS=10000
    depends_on:
      - redis-master
      - redis-slave
    ports: 
       - "26379:26379"
  redis-sentinel-2:
    image: 'bitnami/redis-sentinel:latest'
    container_name: sentinel-2
    environment:
      - REDIS_MASTER_SET=mymaster
      - REDIS_MASTER_HOST=127.0.0.1
      - REDIS_MASTER_PASSWORD=redispassword
      - REDIS_SENTINEL_DOWN_AFTER_MILLISECONDS=10000
    depends_on:
      - redis-master
      - redis-slave
    ports: 
      - "26380:26379"
  redis-sentinel-3:
    image: 'bitnami/redis-sentinel:latest'
    container_name: sentinel-3
    environment:
      - REDIS_MASTER_SET=mymaster
      - REDIS_MASTER_HOST=127.0.0.1
      - REDIS_MASTER_PASSWORD=redispassword
      - REDIS_SENTINEL_DOWN_AFTER_MILLISECONDS=10000
    depends_on:
      - redis-master
      - redis-slave
    ports: 
      - "26381:26379"


9 Ocak 2023 Pazartesi

Docker ve Redis

Örnek
Şöyle yaparız
$ docker run - name redisDemo -d redis
$ docker exec -it redisDev redis-cli
Örnek
Şöyle yaparız
$ docker run --name my-redis -p 6379:6379 -d redis


16 Kasım 2021 Salı

Redis Standalone Mode

Giriş
Açıklaması şöyle
What is a Single Redis Instance?

It’s a solution using the single Redis node deployment architecture.

Standalone Redis Pros:
- Simple and classical architecture.(Image 1)
- Easy deployment and configuration.

Standalone Redis Cons:
- It is not suitable for data reliability requirements.
- There is no backup(slave) node for real-time data synchronization.
- Because Redis is a single-threaded mechanism, its performance is limited by the processing capacity of a single-core CPU. The major bottleneck is the CPU, which restricts the number of instructions that can be performed on a single computer.
Şeklen şöyle


11 Kasım 2021 Perşembe

Redis - List Veri Yapısı

Giriş
List komutları burada. 
- B harfi ile başlayanlar blocking. 
- BL ile başlayanlar, listenin ilk elemanı içindir.
- BR ile başlayanlar listenin son elemanı içindir

Şeklen şöyle. Burada LPUSH, RPOP, DEL görülebilir.


LPUSH
Listenin başına eleman ekler
Örnek
Şöyle yaparız
LPUSH myset 123
LPUSH myset "123"

RPOPLPUSH - Reliable Queue

İlk listenin son elemanını pop ederken, ikinci liste'nin önüne push eder. Açıklaması şöyle
Atomically returns and removes the last element (tail) of the list stored at source, and pushes the element at the first element (head) of the list stored at destination.

For example: consider source holding the list a,b,c, and destination holding the list x,y,z. Executing RPOPLPUSH results in source holding a,b and destination holding c,x,y,z.
Açıklaması şöyle
Lists : they allow us to adopt a worker-queue based approach which can distribute load among worker apps. the messages are removed once they are consumed. it can provide some level of fault-tolerance and reliability using RPOPLPUSH (and BRPOPLPUSH)

12 Ağustos 2021 Perşembe

Redis RediSearch - Secondary Index İçindir

Giriş

Açıklaması şöyle
Redis has a versatile set of data structures ranging from simple Strings all the way to powerful abstractions such as Redis Streams. The native data types can take you a long way, but there are certain use cases that may require a workaround. One example is the requirement to use secondary indexes in Redis in order to go beyond the key-based search/lookup for richer query capabilities. Though you can use Sorted Sets, Lists, and so on to get the job done, you’ll need to factor in some trade-offs.

Available as a Redis module, RediSearch provides flexible search capabilities, thanks to a first-class secondary indexing engine. Some of its key features include full-text search, auto completion, and geographical indexing.
Açıklaması şöyle
Two of the most important commands include creating an index and executing search queries:
FT.CREATE is used to create an index with a given schema and associated details.
FT.SEARCH searches the index with a textual query, returning either documents or just ids.

You can execute other operations on indices:
FT.DROPINDEX deletes the index. Note that by default, it does not delete the document hashes associated with the index
FT.INFO returns information and statistics on the index such as number of documents, number of distinct terms and more.
FT.ALTER SCHEMA ADD adds a new field to the index. This causes future document updates to use the new field when indexing and re-indexing of existing documents.

To work with auto-complete features, you can use “suggestions”:
FT.SUGADD adds a suggestion string to an auto-complete suggestion dictionary.
FT.SUGGET gets completion suggestions for a prefix.

RediSearch supports synonyms which is a data structure comprised of a set of groups, each of which contains synonym terms. FT.SYNUPDATE can be used to create or update a synonym group with additional terms.

If you want query spell check correction (similar to “did you mean” feature), you can use FT.SPELLCHECK which performs spelling correction on a query, returning suggestions for misspelled terms.

A dictionary is a set of terms. Dictionaries can be used to modify the behavior of RediSearch’s query spelling correction, by including or excluding their contents from potential spelling correction suggestions. You can use FT.DICTADD and FT.DICTDEL to add and delete terms, respectively.

Redis Stream Veri Yapısı - Persistent Pub/Sub

Giriş
Stream işleri için JedisPool Sınıfı kullanılır. Understanding Redis Streams yazısına bakılabilir

Açıklaması şöyle.
Redis, meanwhile, recently announced its new data structure, called " Streams," for managing streaming data. Redis Streams offers asynchronous communication between producers and consumers, with additional features such as persistence, look-back queries, and scale-out options — similar to Apache Kafka. In essence, with Streams, Redis provides a light, fast, easy-to-manage streaming database that benefits data engineers.
Persistency vardır. Açıklaması şöyle
Introduced in Redis 5.0, Redis Streams provides the best of Pub/Sub and Lists along with reliable messaging, durability for messages replay, Consumer Groups for load balancing, Pending Entry List for monitoring and much more! What makes it different is that fact it is a append-only log data structure. In a nutshell, producers can add records (using XADD), consumers can subscribe to new items arriving to the stream (with XREAD). It supports range queries (XRANGE etc.) and thanks to consumer groups, a group of apps can distribute the processing load (XREADGROUP) and its possible to monitor its state (XPENDING etc).
Consumer Group'lar şeklen şöyle
Bir başka şekil şöyle. Bu kullanımla aynı Kafka'ya benziyor.

Açıklaması şöyle
Redis Streams messages are string key/values in Java.

Read entries
Açıklaması şöyle
XRANGE
returns the stream entries matching a given range of IDs (the - and + special IDs mean respectively the minimum ID possible and the maximum ID possible inside a stream)
XREVRANGE
is exactly like XRANGE, but with the difference of returning the entries in reverse order (use the end ID first and the start ID later)
XREAD
reads data from one or multiple streams, only returning entries with an ID greater than the last received ID reported by the caller.
XREADGROUP
is a special version of the XREAD command with support for consumer groups. You can create groups of clients that consume different parts of the messages arriving in a given stream
Write Entries
XADD : Yeni veri ekler


Manage Redis Streams
Açıklaması şöyle
XACK
removes one or multiple messages from the Pending Entries List (PEL) of a stream consumer group.
XGROUP
is used to manage the consumer groups associated with a Redis stream.
XPENDING
is the used to inspect the list of pending messages to observe and understand what is happening with a streams consumer groups.
XCLAIM
is used to acquire the ownership of the message and continue processing.
XAUTOCLIAM
transfers ownership of pending stream entries that match the specified criteria. Conceptually, XAUTOCLAIM is equivalent to calling XPENDING and then XCLAIM
Delete
Açıklaması şöyle
XDEL
removes the specified entries from a stream, and returns the number of entries deleted, that may be different from the number of IDs passed to the command in case certain IDs do not exist.
XTRIM
trims the stream by evicting older entries (entries with lower IDs) if needed.
Örnek
Stream kullanmak için bir örnek burada.

5 Ağustos 2021 Perşembe

Redis Cluster Mode With Shards - Availability İçindir

Giriş
Cluster mode kullanırken Sentinel gerekmez. Açıklaması şöyle
You don’t need Sentinel when using Redis cluster.
Redis Cluster performs automatic failover if any problem occur in any primary instance.
Cluster Mode Nedir?
Verinin tek bir düğüme sığmaması ve availability yüzünden dağıtılmasıdır. Açıklaması şöyle
But what if we’re dealing with large data that can’t be contained in one node? Redis supports clusters to shard your data across multiple nodes.
Cluster Mode iki şekilde olabilir
- Sharding with a Redis cluster
- Sharding and Replication with Redis cluster - En çok kullanılan bu

Slots Nedir
The entire keyspace in Redis Clusters is divided into 16384 slots (called hash slots) and these slots are assigned to multiple Redis nodes. A given key is mapped to one of these slots and the hash slot for a key is computed:

HASH_SLOT = CRC16(key) mod 16384

In most cases, you don’t need to know these internals as Redis will take care of the push and pull of data from the right cluster.
Açıklaması şöyle
Redis Cluster does not use consistent hashing, but a different form of sharding where every key is conceptually part of what we call a hash slot. There are 16384 hash slots in Redis 
Cluster, and to compute what is the hash slot of a given key, we simply take the CRC16 of the key modulo 16384. Every node in a Redis Cluster is responsible for a subset of the hash slots, so for example you may have a cluster with 3 nodes, where:

- Node A contains hash slots from 0 to 5500.
- Node B contains hash slots from 5501 to 11000.
- Node C contains hash slots from 11001 to 16383.

1. Sharding With Cluster Nedir?
Açıklaması şöyle. Yani verinin dağıtılmasıdır.
If data is to be sharded to several nodes, Redis offers an open-source version of Redis Cluster. It supports building a cluster from several replication groups. Data within the cluster is sharded over 16 384 slots. Slot ranges are determined among Redis nodes.

Nodes within the cluster communicate over a separate open port to know their neighbors’ statuses. To work with Redis Cluster, the app should use a special connector.
Şeklen şöyle.


2. Sharding And Replication With Cluster Nedir?
Şeklen şöyle. Yani verinin dağıtılması ve her düğümün de replica'sının olmasıdır
Şeklen şöyle
Açıklaması şöyle
What is the Redis Cluster?

Data is automatically partitioned over many Redis nodes, resulting in a stable and reliable data service. So automatically split your dataset among multiple nodes. A cluster must have at least three master nodes to work correctly, with Redis recommending that each master have at least one slave and requires Redis version 3.0 or higher.

Every node should open two TCP connections. The standard Redis TCP port for serving clients. The second port is utilized for the Cluster bus, which is a binary protocol-based node-to-node communication.

If a master instance becomes unavailable due to network failures or software/hardware failures, the other Master nodes will notice by the Cluster bus and reach a failover state. After then, a suitable slave of the unavailable Master node will step forward and be promoted to become the new Master.
Cluster istemciyi doğru sunucuya yönlendirir. Açıklaması şöyle
In Redis Cluster nodes don't proxy commands to the right node in charge for a given key, but instead, they redirect clients to the right nodes serving a given portion of the keyspace. 
İyi ve kötü yönleri şöyle

Redis Cluster Pros:
- It has no central architecture, automatically splits data among multiple nodes.
- Data is distributed among several nodes based on a hash slot, and data distribution can be adjusted dynamically.
- Scalability: Add and remove nodes in the cluster easily. Nodes can be added or removed dynamically, and the system can scale up to 1000 nodes.
- Automatic failover can be done by using Slave as a standby data copy. Because of supports the master-slave structure, you don’t need any additional failover handling, it has built-in failover of the master;

Redis Cluster Cons:
- You need at least 6 nodes — 3 master and slave
- Not entirely highly available, the cluster will stop down if the majority of masters are unavailable in the case of a bigger failure.
- Data is replicated asynchronously, and there is no guarantee of data consistency.
- Because the replication structure only allows one layer, the slave node can only duplicate the master node.
- Because data is sharded among the masters, clients should have network access to all nodes in a Redis Cluster. If a client wants to write data to Master1 but the data belongs to Master2, Master1 will give the client a MOVE message, directing it to forward the request to Master2.
- Not every library supports; the lack of client library implementations in Redis Cluster.
- It is not possible to ensure a strong consistency. In practice, this means that Redis Cluster may lose writes that were acknowledged by the system to the client under certain circumstances.
- Because of data partitioning, data handling becomes more complicated; for example, you should handle multiple RDB / AOF files, and you need to aggregate the persistence files from multiple instances and hosts to generate a backup of your data. It is not possible to manage backups from a single location.


Redis sentinel.conf Dosyası

monitor Alanı
Şöyle yaparız
sentinel monitor redis-cluster 172.18.0.2 6379 2
Açıklaması şöyle
Sentinels only need to look at primary nodes to decide on failover.
down-after-milliseconds Alanı
Açıklaması şöyle
We can use below config to decide on how long before a cluster node is considered down.
Şöyle yaparız
sentinel down-after-milliseconds redis-cluster 5000
failover-timeout Alanı
Açıklaması şöyle
We can add below to allow timeout for current replication writes to complete before a failover kick-off:
Şöyle yaparız
sentinel failover-timeout redis-cluster 10000



3 Ağustos 2021 Salı

Redis - RedisTimeSeries

Giriş
Açıklaması şöyle
RedisTimeSeries is a Redis Module that brings native Time Series data structure to Redis. Time Series solutions which were earlier built on top of Sorted Sets (or Redis Streams) can benefit from RedisTimeSeries features such as high volume inserts, low latency reads, flexible query language, down-sampling and much more!
TS.ADD
Örnek
Şöyle yaparız
# temperature for device 2 in location 3 along with labels
TS.ADD temp:3:2 * 20 LABELS metric temp location 3 device 2 # pressure for device 2 in location 3 TS.ADD pressure:3:2 * 60 LABELS metric pressure location 3 device 2`
TS.GET
Örnek
Şöyle yaparız
# pressure in device 5 for location 1
TS.GET pressure:1:5

# temperature in device 5 for location 4
TS.GET temp:4:5
TS.MRANGE
Ortalamayı gösterir
Örnek
Açıklaması şöyle
Extract temp and pressure for all devices in one or more locations within a specific time range:
Şöyle yaparız
TS.MRANGE - + WITHLABELS FILTER location=3
TS.MRANGE - + WITHLABELS FILTER location=(3,5)


2 Ağustos 2021 Pazartesi

Redis - Geospatial Indexes

Giriş
Açıklaması şöyle. Sorted Set Veri Yapısı yazısına bakabilirsiniz.
- Redis provides commands like GEOADD, GEORADIUS, GEORADIUSBYMEMBER, GEOSEARCH, and GEOSEARCHSTORE for geospatial indexing and searching.

- The spatial entities are stored in Sorted Sets using the coordinates to form 52-bit integers using the Geohash technique.
Açıklaması şöyle.
- Redis uses Haversine formula to calculate the distances as the model assumes that the Earth is a sphere. This can result in an error of up to 0.5%.

Valid longitudes range from -180 to 180 degrees, while valid latitudes range from -85.05112878 to 85.05112878 degrees.

GEOADD Komutu
Bir yeri eklemek için kullanılır
Örnek
Şöyle yaparız
> GEOADD places -122.419 37.774 “San Francisco”
> GEOADD places -122.143 37.441 “Palo Alto”
> GEOADD places -122.083 37.386 “Mountain View”
> GEOADD places -121.886 37.338 “San Jose”
GEORADIUS Komutu - Arama İçindir
Açıklaması şöyle
To perform a spatial search of entities GEORADIUS or GEORADIUSBYMEMBER can be used in Redis 3.2.0 (and above) and GEOSEARCH or GEOSEARCHSTORE can be used in Redis 6.2 (and above).

The time complexity for these commands is approximately O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius, and M is the number of items inside the index.
Örnek
Şöyle yaparız
> GEORADIUS places -122.228 37.484 50 mi COUNT 1 ASC WITHCOORD WITHDIST
1) 1) "Palo Alto" 2) "5.5294" 3) 1) "-122.14300006628036499" 2) "37.4410011922460555"
GEORADIUSBYMEMBER Komutu - Arama İçindir
Örnek
Şöyle yaparız
> GEORADIUSBYMEMBER places "Mountain View" 20 mi WITHDIST
1) 1) "Mountain View"
   2) "0.0000"
2) 1) "Palo Alto"
   2) "5.0297"
3) 1) "San Jose"
   2) "11.3186"
Örnek
Şöyle yaparız
> GEORADIUSBYMEMBER places "Mountain View" 50 mi WITHDIST
1) 1) "San Francisco" 2) "32.5234" 2) 1) "Mountain View" 2) "0.0000" 3) 1) "Palo Alto" 2) "5.0297" 4) 1) "San Jose" 2) "11.3186"
ZCARD Komutu
Açıklaması şöyle.
Since these entities are stored in a sorted set, the ZCARD command would return the total count of spatial entities.
Örnek
Şöyle yaparız
> ZCARD places
(integer) 4
ZRANGE Komutu 
Tüm elemanları gösterir
Örnek
Şöyle yaparız.
> ZRANGE places 0 -1
1) "San Francisco"
2) "Mountain View"
3) "Palo Alto"
4) "San Jose"

Redis Serializers

JSON Serializer
Veriyi JSON olarak saklamak iyi bir fikir değil. Açıklaması şöyle
Using JSON to store data in Redis will increase your latency and resource usage without bringing any real benefit.
Bazı sebepler şöyle
- JSON serialization/deserialization is incredibly inefficient and costly
- You end up using more space in storage (which is expensive in Redis since it’s an in-memory database)
- You increase your overall service latency without any real benefit
MsgPack

Sıkıştırma

Redis Sentinel Mode - Sadece Master Düğümün Replica'ları Var

Giriş
Sentinel ve Clustter mod farklı şeyler. Açıklaması şöyle. 
The sentinels are different concept than Redis cluster. If the primary dies then sentinels talk to each other to decide new primary.
Sentinel Nedir?
Açıklaması şöyle
It’s a solution that makes it easier to manage Redis instances. Since Redis 2.8, a stable release of Redis Sentinel has been available. Sentinel is a separate application that runs in the background. It will monitor your master and slave instances, alert you to any changes, manage automated failover in the event of a master failure, and perform as a configuration provider.
Şeklen şöyle

Sentinel'ler bir araya gelerek yeni Replica Set için Master'ı seçer. Açıklaması şöyle. 
Redis nodes can be interconnected by means of asynchronous replication. We’ll call such nodes a replica set. It is Redis Sentinel that manages the replica set. Redis Sentinel is one special process or several of them clustered, to monitor Redis nodes. They perform 4 primary tasks:

- Checking node status within the group - dead or alive.

- Notifying the system administrator if something goes wrong within the group.

- Automatic switching of the master.

- Config provider for external clients for them to know where to connect.
Yani 3 tane önemli görev var. Bunlar
1. Monitoring
2. Automatic failover
3. Configuration provider

Redis Primary-Secondary (Replica) Network with Sentinel without Sharding
Açıklaması şöyle. Bu modda veri dağıtılmıyor. Sadece master düğümün replica'ları var.
In scenarios where you don’t need sharding and one node is enough for your in-memory needs, you can avoid creating clusters and build primary-secondary replicas by specifying the replicaof in the replica configurations for the Redis node.

If we’re not using Redis clusters then we need sentinels to achieve failovers.
Master ve Replica şeklen şöyle
İyi ve kötü yanları şöyle
Redis Sentinel Pros:
- With three nodes, you can build up a fully functional Sentinel deployment. (Image 2)
- Simplicity - it’s usually simple to maintain and configure.
- Highly available, you can build a Redis Sentinel deployment that can survive certain failures without any need for human intervention.
- Work as long as a single master instance is available; it can survive the failure of all slave instances.
- Multiple slave nodes can replicate data from a master node.

Redis Sentinel Cons:
- Not scalable; writes must go to the master, cannot solve the problem of read-write separation.
- Slaves may serve reads, but because of asynchronous replication, outdated reads may result.
- It doesn’t shard data, so master and slave utilization will be imbalanced.
- The slave node is a waste of resources because it does not serve as a backup node.
- Redis-Sentinel must be supported by the client. The client holds half of the magic.

Sentinel Sayısı ve Quorum
Açıklaması şöyle. En az 3 sentinel kullanılır. Quorum sayısı sentinel sayısından az olabilir.
Sentinel documentation states that at least three sentinel instances are required for robust deployment. Although they can run as parallel processes in the same Redis instance, they should be placed into servers or VMs that are believed to fail independently.

Sentinel constantly checks the master for a failure. If enough sentinel agrees that the master is down then it acts as an authority and will start a failover process. As a result, it will promote a replica to be the master, configure other replicas to use new master until the master node is reachable again.

Sentinel agreement depends on the quorum value. Quorum value is the minimum number of the sentinels agree that the master is not reachable now. For 3 sentinel instances, the usual quorum value is 2.
Açıklaması şöyle
Quorum is configurable which only refers to the number of sentinels who must agree when a master is down. When in a failover scenario, sentinel instances attempt to reach a consensus, and at least three (odd number) sentinel instances will prevent most problems. These three Sentinel instances should also be placed on separate physical servers or Virtual Machines, as they are expected to fail in independent ways. 
Sentineller şeklen şöyle


Bağlantı
Açıklaması şöyle. Sentinel'ler kendi aralarında konuşmak için 26379 numaralı portu kullanır
The default port for Sentinel is 26379, so for sentinel instance to work, port 26379 of your servers must be open to receive connections from the IP addresses of the other sentinel instances. Otherwise, these instances can’t talk and agree about what to do, so failover will never be performed.
Bağlantı Timeout
Açıklaması şöyle.
You can configure the time required to check the master is down or not. Find down-after-milliseconds command which is the time in milliseconds to an instance should not be reachable for a Sentinel starting to think it is down. The default value is 30000 ms and you can change it as you like.

sentinel down-after-milliseconds mymaster 10000
Down Kavramı
Açıklaması şöyle.
Sentinel has two concepts of being down. Subjectively Down (SDOWN) condition is the local sentinel instance node thinks that Master is down. Objectively Down (ODOWN) condition is if enough instances (when quorum met) agree that the Master is not reachable.

Configure Sentinel to observe the Master with a specified quorum number.
# sentinel monitor <master-group-name> <ip> <port> <quorum>
sentinel monitor mymaster 127.0.0.1 6379 2
Çalıştırma
Şöyle yaparız
redis-sentinel /path/to/redis-sentinel*.conf