Original: Http://stackoverflow.com/questions/7888880/what-is-redis-and-what-do-i-use-it-for
Redis = Remote Dictionary Service
Tl;dr:if you can map a use case to Redis and discover you aren ' t @ risk of running out of RAM by using Redis there is a Good chance you should probably use Redis.
It ' s a "NoSQL" Key-value data store. More precisely, it's a data structure server.
Not as MongoDB (which is a disk-based document store), though MongoDB could are used for similar key/value use cases.
The closest analog is probably to think of Redis as Memcached, but with built-in persistence (snapshotting or Jou Rnaling to disk) and more datatypes.
Those additions may seem pretty minor, but they is what make Redis pretty incredible. persistence to disk means your can use Redis as a real database instead of just a volatile cache. The data won ' t disappear when you restart, like with memcached.
The additional data types is probably even more important. Key values can is simple strings, like you'll find in memcached, but they can also is more complex types like hashes, List S (ordered collection, makes a great queue), sets (unordered collection of non-repeating values), or Sorted sets (ordered/ Ranked collection of non-repeating values).
This was only the tip of the Redis iceberg, as there was other powerful features like built-in Pub/sub, transactions (with Optimistic locking), and Lua scripting.
The entire data set, like memcached, are stored in-memory so it's extremely fast (like memcached) ... often even faster tha n memcached. Redis had virtual memory, where rarely used values would be swapped off to disk, so only the keys had to fit into memory, But this has been deprecated. Going forward the use cases for Redis is those where its possible (and desirable) for the entire data set to fit into mem Ory.
Redis is a fantastic choice if you want a highly scalable data store GKFX by multiple processes, multiple applications, or multiple servers. As just an inter-process communication mechanism it's tough to beat. The fact that you can communicate cross-platform, cross-server, or cross-application just as easily makes it a pretty grea T choice for many many use cases. Its speed also makes it great as a caching layer.
Update 4/1/2015: Redis 3.0 (Stable) was released today. This version of the Redis brings cluster support, which makes it much easier to scale Redis.
@acidzombie24 its possible your could use of Redis in-place-of MySQL but it really depends on the use case. If your data set could grow to 20GB or your need to use some business analytic tools, you need to make heavy use of joins, etc. then it might don't make sense. It's really hard-make a blanket statement except to say that there is certainly cases where Redis would be appropriate In place of MySQL.
@KO. Just like Redis offers features which memcached doesn ' t, RDBMS offers many many features which Redis does not. Redis should is far faster than any RDBMS, but it also can ' t do as much. If you can map the your RDBMS use case to Redis then it might is worth taking a look, and if you can ' t do not force it. Best tool for the job and all that. A no-sql store that have a better chance of replacing your RDBMS is MongoDB, but even the needs to be evaluated carefully Should go with the best fit, which is an RDBMS
A very thought-provoking thread here. Being an old dog, it's quite a thunder-clap when I realized the reason most data are now persisted to DBs is simply Becau Se a whole generation of programmers has grown up with cheap, ubiquitous DBs and they don ' t KNOW all other it's the persist ing data. No clue what Qsort () & Bsearch () is capable of for example. Re:joins with Redix, if people knew how simple it was to do joins in memory they ' d was shocked. The data value you join on simply becomes a token of that was replaced by the data the FK indexes. It ' s ~ String replacement problem
dbs is wonderful, and very flexible, but horribly expensive in terms of resources, and very Slow. Slow, not because the internals aren ' t fast, but because they has a large fixed cost which are realized as a lot of latenc Y. As an example, my employer have an ENUM server with a latency-good by industry standards. I am writing a CPS throttle with. 067 microsecond latency. Not even in the same ballpark. Likewise, bsearch () against a pointer array, the result of a PTR qsort (), and fetching data from SSDs, is thousands of Tim Es faster than any db-even in-memory ones like ours.
With respect to Redix-holding indexes in memory, with SSDs, I-hope this option is still available. The latest generation of SSD focused RAIDs by Adaptec (ASR-8885 RAID) and LSI perform at 12gbps-spectacular for 256-2k BYTE random I/Os A data structure server would be fetching. The reason so many alternative-to-SQL, like NoSQL, was showing up, was because SQL is the problem. Too much parsing, Too much data conversion, metadata driving the very internals of your database, and Too much conversion Again on the backend. With data structures, the answer before the SQL gets to the NIC
109 Down vote |
What is it can be? Few examples from http://highscalability.com/blog/2011/7/6/11-common-web-use-cases-solved-in-redis.html:
- Show Latest Items listings in your home page. This was a live in-memory cache and is very fast. Lpush is used to insert a content ID at the head of the list stored at a key. LTRIM is used to limit the number of items in the list to 5000. If the user needs to page beyond this cache, then is they sent to the database.
- deletion and filtering. If a cached article is deleted it can be removed from the cache using Lrem.
- leaderboards and related problems. A leader board is a set of sorted by score. The Zadd commands implements this directly and the Zrevrange command can is used to get the top of the users by score and ZRA NK can is used to get a users rank. Very direct and easy.
- Order by user votes and time. This was a leaderboard like Reddit where the score was formula the changes over time. Lpush + LTRIM is used to the add an article to a list. A Background Task Polls the list and recomputes the order of the list and Zadd is used to populate the list in the new Ord Er. This list can is retrieved very fast by even a heavily loaded site. This should is easier, the need for the polling code isn ' t elegant.
- Implement expires on items. To keep a sorted list by time and use Unix time as the key. The difficult task of expiring items are implemented by indexing current_time+time_to_live. Another background worker is used to make queries using Zrange ... with SCORES and delete timed out entries.
- counting stuff. Keeping stats of all kinds are common, say you want to know when to block an IP addresss. The Incrby command makes it easy to atomically keep counters; Getset to atomically clear the counter; The expire attribute can be used to tell when a key should be deleted.
- Unique N items in a given amount of time. This is the unique visitors problem and can be solved using Sadd for each pageview. Sadd won ' t add a member to a set if it already exists.
- Real time analysis of what are happening, for stats, anti spam, or whatever. Using Redis Primitives It ' s much simpler to implement a spam filtering system or other real-time tracking system.
- pub/sub. Keeping a map of who are interested in updates to what data is a common task in systems. Redis have a pub/sub feature to make this easy using the commands like SUBSCRIBE, unsubscribe, and PUBLISH.
- Queues. Queues is everywhere in programming. In addition to the push and pop type commands, Redis have blocking queue commands so a program can wait for work being added To the queue by another program. You can also does interesting things implement a rotating queue of RSS feeds to update.
- Caching. Redis can be used in the same manner as memcache.
|
Yet another one:a very simple, but useful tool for programmers. A build-counter Server. Eg. Your application version may 1.2.7 (build #473). It's very easy-to-add a new build number for your project, and your build-script can easily request a new (unique) number.
Oh, and it's awfully easy-to-use this for making-scripts that run on the different platforms communicate with Eachothe R. For instance one of those cortex-a based tv-boxes can send data back and forth to my desktop computer-so I ' m using it Like a FIFO.
Go to what's Redis and what does I use with it for?