Redis compared with Memcache and Ehcache

  • For applications with persistence requirements or advanced requirements on data structure and processing, select Redis and memCache for other simple key/value storage.
  • Memcache is suitable for reading more than writing, and large amount of data (such as renren’s massive query of user information, friends’ information, article information, etc.)
  • Redis is suitable for systems with high requirements on read and write efficiency, complex data processing operations and high requirements on security (such as the counting and publishing systems of Sina Weibo, which have high requirements on data security and read and write).
  • Ehcache is directly cached in the JVM, which is fast and efficient. However, cache sharing is troublesome and cluster distributed application is inconvenient. Suitable for a single application or applications that require high cache access.
  • Think of Memcache as a large memory HashTable. You can think of Redis as an extension of Memcached, a more heavyweight implementation that provides more and more powerful functionality.
  • Use cases:
    • Memcache: Netflix, Facebook
    • Redis: Sina, Taobao, GitHub

The keys and values of Redis are redisObject objects, and each object has type, encoding, and PTR. Encoding is associated with the underlying data structure:

You can see which key values are encoded by entering the Object Encoding key name on the Redis command line.

The Redis cache service is deployed in Linux

Step 1 Use wget to download the gz package from the official website, for example:

Wget HTTP: / / https://download.redis.io/releases/redis-6.2.3.tar.gz

Step 2 If it is Ali Cloud server, there may be a lack of pkg-config software, you need apt-get update, and then apt-get install PKg-config. Decompress the Redis package (recommended in /usr/local), CD it to the decompressed directory, and make && make install

Step 3 (optional, caution, custom recommended) Execute the script in the compressed package to set Redis as a background service.

[root@localhost redis-6.2.3]# CD utils/ [root@localhost utils]#./install_server.shCopy the code

Step 4 Run redis-server to start the service. It is strongly recommended to specify the configuration file explicitly. Conf file in the installation directory. If this file is not explicitly specified during startup, the configuration does not take effect. The configuration file can be placed anywhere, just take the path of the configuration file with the redis-CLI during startup. Execute redis-cliset and get to see if they are successful.

Step 5 Allow remote connections:

  1. Ali Cloud security policy firewall set release.
  2. Vim configuration file. Conf, protected-mode set to noThe bind 127.0.0.1Commented out.

Step 6 (optional) Set the access password. Change # requirePass foobared in the configuration file to requirepass your password and restart the Redis service. At the Redis command prompt auth your password to log in.

Common configuration optimizations:

  1. Set vM-enabled in redis. Conf to no (to disable virtual memory).
  2. Set the maxMemory option in redis. Conf, which tells Redis to reject subsequent write requests after using too much physical memory. This parameter will protect your redis from using too much physical memory, resulting in severe performance impact and even crash.