Redis for caching scenarios

Source: Internet
Author: User
Tags download redis install redis

About Redis

?? Redis is an abbreviation for the Remote Dictionary Server (Redis), and maybe you can guess what it's about by listening to your name. Yes, it is a Key-value storage system written by Salvatore Sanfilippo, a Key-value database that is written in ANSI C, complies with BSD protocol, supports the network, and can be persisted based on memory. and provides APIs in multiple languages. In many places, Redis is also known to the industry as a data structure server because it allows the cached values (value) to be a string, hash, list, collection (set), and an ordered set (sorted set). In addition, Redis supports Master-slave-mode data backup, all of which make Redis stand out in the same type of product.

The benefits of Redis
    • Extremely high Performance – perform a Redis benchmark (benchmark) on my Mac book Pro, capable of handling write operations of more than 80000 per second. Some of the test results are as follows:

    • Rich data types –redis support strings, Lists, hashes, sets and ordered sets data type operations.
    • All atomic –redis operations are atomic, and Redis supports atomic execution of several operations.
    • Rich features –redis also support publish/subscribe, notifications, key expiration and other rich features.
Installation and configuration of Redis

?? How to install Redis on Windows and Linux systems The W3cschool website has been explained in detail, and I share the process of installing Redis on Mac, which is basically consistent with other systems. First download Redis's compressed files from the Redis official website, and then have a src directory after decompression. Because Mac system is developed on the basis of Unix system (FreeBSD), it is possible to build the source code of SRC directory directly using make command (makefile is definitely already there, do not understand the role and principle of make do not matter, do as you can), After the build is completed, a redis-server file is generated in the SRC directory, and the server can be started by running it as shown in.

?? Next, you can start a client program to do some simple experiments. Or in just the SRC directory there is a redis-cli file, run it can start a client, as shown in.

?? Information about Redis data types, commands, transactions, publish/subscribe, data Backup and restore, configuration, and more can still be found in the W3cschool Web site mentioned above.

Using Redis in a Java project

Jedis is the official Redis preferred Java Client Development package, and the relevant API documentation can be obtained by clicking on the link. A simple test code is given below.

 import Redis.clients.jedis.Jedis; class redistest {     Public Static voidMain (string[] args) {Jedis Jedis =NewJedis ("localhost");//Connect to Redis server        //Jedis.auth ("123456"); Enter a password to verifyJedis.Set("Greeting","Hello, world!.");//cache string to Redis serverSystem.out.println (Jedis.Get("Greeting"));//Get data from the Redis cache}}
Comparison of Redis and memcached
    1. The best way to use Redis is to in-memory all data.
    2. Redis more scenes are used as substitutes for memcached.
    3. Redis is more appropriate when it is necessary to support more data types than Key/value.
    4. Redis is more appropriate when the stored data cannot be rejected.
    5. Redis can use directives to perform operations on cached data directly.

Redis for caching scenarios

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.