10 items | 3 visits
Useful libraries for web dev
Updated on Mar 07, 13
Created on Jun 29, 12
Category: Computers & Internet
URL:
Phosphor is a new way to bring animation and video to the web.
Example use case for Redis over other conventional data stores.
"Using Redis To Improve Performance
This caching technique can be effective but if the user’s searching for a term that isn’t cached the response will take longer as not only does the database query need to be made, the results also need to be written to the cache store. At this point we might start looking for a different storage engine for the autocompletion to replace the SQL database. One such option is Redis which is an advanced in-memory key-value store which is very fast and which has some features that will suit our needs perfectly, such as sorted sets. With it we can add records to a sorted set and assign a value to each one so that it’s sorted. We can then use ZRANGE to fetch the set in the right order later. Let’s say that we want to index the term “food”. We could make a separate set for each partial match of that word (“f”, “fo” and “foo”) and when a user starts typing the word “food” we can look up a set with that name. If we index multiple terms that start with “foo” these would also be returned, sorted by their score. We can use ZREVRANGE to do this to return them in reverse order of score so that the most popular are returned first. To add an item to a set we use ZADD but we can also use ZINCRBY to increment the score for an item that already exists. This will be useful to us as a way to increase the popularity of a given term.
To try this out we’ll need to install Redis. If you’re running OS X the easiest way to do this is to use Homebrew. Redis can then be installed by running brew install redis. We can then start it up by running this command."
This caching technique can be effective but if the user’s searching for a term that isn’t cached the response will take longer as not only does the database query need to be made, the results also need to be written to the cache store. At this point we might start looking for a different storage engine for the autocompletion to replace the SQL database. One such option is Redis which is an advanced in-memory key-value store which is very fast and which has some features that will suit our needs perfectly, such as sorted sets. With it we can add records to a sorted set and assign a value to each one so that it’s sorted. We can then use ZRANGE
to fetch the set in the right order later. Let’s say that we want to index the term “food”. We could make a separate set for each partial match of that word (“f”, “fo” and “foo”) and when a user starts typing the word “food” we can look up a set with that name. If we index multiple terms that start with “foo” these would also be returned, sorted by their score. We can use ZREVRANGE
to do this to return them in reverse order of score so that the most popular are returned first. To add an item to a set we use ZADD but we can also use ZINCRBY
to increment the score for an item that already exists. This will be useful to us as a way to increase the popularity of a given term.
To try this out we’ll need to install Redis. If you’re running OS X the easiest way to do this is to use Homebrew. Redis can then be installed by running brew install redis
. We can then start it up by running this command.
10 items | 3 visits
Useful libraries for web dev
Updated on Mar 07, 13
Created on Jun 29, 12
Category: Computers & Internet
URL: