-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_notes.properties
127 lines (84 loc) · 2.74 KB
/
redis_notes.properties
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
Redis
- Remote Dictionary
- Open source in-memory data structure
- saves transient data
- can be used as a database or cache or message broker
- NoSQL key/value store
- supports multiple data structures
- built in replication
- Works on master slave concept
Redis Data types
- a big range
- Strings
- Lists
- Sets
- Sorted Sets
- Hashes
- Bitmaps
- HyperLogs
- Geospatial Indexes
Advantages of Redis
- Very flexible
- No schema and column names
- Very fast
- Caching and Disk persistence
- Combination of MongoDB and Memcached
Redis Security
- Should be used internally
- Should not be exposed to internet
- no data encryption
- only trusted clients can access redis
Redis Hashes
- map for string fields and values
- redis can store upto 4 billion field value pairs
- stores multiple values
- key is a string
- value is a map
Redis Lists
- list of strings sorted by insertion order
- elements can be inserted in top or bottom
- list has head and tail
- head is on the left side and tail on the right side
Redis Sets
- unordered collection of unique strings
Redis Sorted Sets
- unique and sorted
- every members have a score
- based on the score, the numbers are sorted
Redis Publish Subscribe
- implements messaging system with publisher and subscriber
- can subscribe to any number of channels
Features/Estimation for setting up Distributed Cache
- Data size
- QPS (Query per second)
- Latency
- LRU (eviction policy)
- 100% Availability
- Scalable
Cache Access Patterns
1. Write Through
- write request goes through cache and then goes to DB
- ack is sent only when the data is saved both in cache and the db
2. Write Around
- Write request will go to DB around the cache. It will not store data in cache
- Data is stored in cache only when there is a cache miss during read request.
3. Write Back
- The write will go to cache and ack is sent. It will not store data in cache
- Later another service will store data asynchronously to DB
Cache Eviction Policy
- removing key value pair from cache which ar enot used
LRU (Least Recently Used)
- the key value pair which are not used.
- to implement LRU we need a hashtable and a bidirectional linked list
- bidirectional linked list will store the keys on the order
- the items in the beginning of the list are least recently used
- If an item is accessed again and again, the old element is removed and added in the right side as a new entry
- Birectional linked list search and remove is O(1)
Fault Tolerance
1. Regular Interval Snapshot
Saving snapshots of hashtable from RAM to DB
2. Log Reconstruction
All the read and write operations with key values are logged in to the log file. Whole data can be reconstructed from the log file
Availability
- Replication
- Master Slave