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
- The best way to use Redis is to in-memory all data.
- Redis more scenes are used as substitutes for memcached.
- Redis is more appropriate when it is necessary to support more data types than Key/value.
- Redis is more appropriate when the stored data cannot be rejected.
- Redis can use directives to perform operations on cached data directly.
Redis for caching scenarios