You can use Redis as an authoritative store in a number of different ways:
Turn on AOF (Append-only File store) see AOF docs . This will keep a log of all Redis commands made against your dataset in real-time.
Run Redis using Master-Slave replication see replication docs . This will allow you to provide high-availability if one of your instances fails.
If you're running on something like EC2 you can EBS back your Redis partition to provide another layer of protection against instance failure.
On the horizon is Redis Cluster - this is specifically designed as a way to run Redis in a way that should help with HA and scalability. However, this won't appear for at least another six months or so.
As Redis is an in-memory storage, you cannot store large data that won't fit you machine's memory size. Redis usually work very bad when the data it stores is larger than 1/3 of the RAM size. So, this is the fatal limitation of using Redis as a database. Certainly, you can distribute you big data into several Redis instances, but you have to do it all on your own manually. The operation usually be done like this(assuming you have only 1 instance from start):
Use its master-slave mechanism to replicate data to the second machine, Now you have 2 copies of the same data.
Cut off the connection between master and slave.
Delete the first half(split by hashing, etc) of data on the first machine, and delete the second half of data on the second machine.
Tell all clients(PHP, C, etc...) to operate on the first machine if the specified keys are on that machine, otherwise operate on the second machine. This is the way how Redis scales! You also have to stop your service to prevent any writes during the migration. To the expierence we encounter, we have this conclusion to Redis: Redis is not the right choice to store more than 30G data, Redis is not scalable, Redis is quite suitable for prototype development. We later find an alternative to Redis, that is SSDB( https://github.com/ideawu/ssdb ), a leveldb server that supports nearly all the APIs of Redis, it is suitable for storing more than 1TB of data, that only depends on the size of you harddisk.
Redis is a database, that means we can use it for persisting information for any kind of app, information like user accounts, blog posts, comments and so on. After storing information we can retrieve it later on by writing queries. Now this behavior is similar to just about every other database, but what is the difference? Or rather why would we use it over any other database? Redis is fast. Redis is not fast because its written in a special programming language or anything like that, its fast because all data is stored in-memory. Most databases store all their information between both the memory of a computer and the hard drive. Accessing data in-memory is fast, but getting it stored on a hard disk is relatively slow. So rather than storing memory in hard disk, Redis decided to store it in memory. Now, the downside to this is that working with data that is larger than the amount of memory your computer has, that is not going to work. That may sound like a tremendous problem, but Redis has clear strategies for working around this limitation. The above is just the first reason why Redis is so fast. The second reason is that Redis stores all of its data or rather organizes all of its data in simple data structures such as Doubly Linked Lists, Sorted Sets and so on. These data structures have well-known and well-understood performance characteristics. So as developers we can decide exactly how our information is organized and how to efficiently query data. Its also very fast because Redis is simple in nature, its not feature heavy, feature heavy datastores like Postgres has performance penalties. So to use Redis as a database you have to know how to store in limited space, you have to know how to organize it into these simple data structures mentioned above and you have to understand how to work around the limited feature set. So as far as mitigating risks, the way you start to do that is to start to think Redis Design Methodology and not SQL Database Design Methodology. What do I mean? So instead of, step 1. Put the data in tables, step 2. figure out how we will query it. With Redis its more: Step 1. Figure out what queries we need to answer. Step 2. Structure data to best answer those queries.
5条答案
按热度按时间7ivaypg91#
You can use Redis as an authoritative store in a number of different ways:
On the horizon is Redis Cluster - this is specifically designed as a way to run Redis in a way that should help with HA and scalability. However, this won't appear for at least another six months or so.
nkoocmlb2#
Redis是一个内存存储,它也可以将数据写回光盘。你可以指定执行fsync的次数,以使Redis更安全(但也更慢=〉权衡)。
但是我仍然不确定redis是否已经进入了真正存储关键数据的状态。例如,如果再多一条tweet(twitter.com)或类似的东西丢失不是一个大问题,那么我肯定会使用redis。在redis自己的网站上也有很多关于persistence的信息。
你也应该知道some persistence problems,这可能发生在阅读antirez(redis维护者)的博客文章。你应该阅读他的博客,因为他有一些有趣的文章。
nx7onnlm3#
As Redis is an in-memory storage, you cannot store large data that won't fit you machine's memory size. Redis usually work very bad when the data it stores is larger than 1/3 of the RAM size. So, this is the fatal limitation of using Redis as a database.
Certainly, you can distribute you big data into several Redis instances, but you have to do it all on your own manually. The operation usually be done like this(assuming you have only 1 instance from start):
This is the way how Redis scales! You also have to stop your service to prevent any writes during the migration.
To the expierence we encounter, we have this conclusion to Redis: Redis is not the right choice to store more than 30G data, Redis is not scalable, Redis is quite suitable for prototype development.
We later find an alternative to Redis, that is SSDB( https://github.com/ideawu/ssdb ), a leveldb server that supports nearly all the APIs of Redis, it is suitable for storing more than 1TB of data, that only depends on the size of you harddisk.
brccelvz4#
我想分享一下我们在使用Redis作为我们服务的主数据库时学到的一些东西。我们选择Redis是因为我们的数据不能被分区。我们想从一个盒子里得到最好的性能
优点:
缺点:
wwtsj6pe5#
Redis is a database, that means we can use it for persisting information for any kind of app, information like user accounts, blog posts, comments and so on. After storing information we can retrieve it later on by writing queries.
Now this behavior is similar to just about every other database, but what is the difference? Or rather why would we use it over any other database?
Redis is fast.
Redis is not fast because its written in a special programming language or anything like that, its fast because all data is stored in-memory.
Most databases store all their information between both the memory of a computer and the hard drive. Accessing data in-memory is fast, but getting it stored on a hard disk is relatively slow.
So rather than storing memory in hard disk, Redis decided to store it in memory.
Now, the downside to this is that working with data that is larger than the amount of memory your computer has, that is not going to work.
That may sound like a tremendous problem, but Redis has clear strategies for working around this limitation.
The above is just the first reason why Redis is so fast.
The second reason is that Redis stores all of its data or rather organizes all of its data in simple data structures such as Doubly Linked Lists, Sorted Sets and so on.
These data structures have well-known and well-understood performance characteristics. So as developers we can decide exactly how our information is organized and how to efficiently query data.
Its also very fast because Redis is simple in nature, its not feature heavy, feature heavy datastores like Postgres has performance penalties.
So to use Redis as a database you have to know how to store in limited space, you have to know how to organize it into these simple data structures mentioned above and you have to understand how to work around the limited feature set.
So as far as mitigating risks, the way you start to do that is to start to think Redis Design Methodology and not SQL Database Design Methodology. What do I mean?
So instead of, step 1. Put the data in tables, step 2. figure out how we will query it.
With Redis its more:
Step 1. Figure out what queries we need to answer. Step 2. Structure data to best answer those queries.