memcached Introduction, installation and basic use

Source: Internet
Author: User
Tags delete key

Memcached is a high-performance distributed memory object caching system for dynamic Web applications to mitigate database load. It provides a dynamic, database-driven site speed by caching data and objects in memory to reduce the number of times the database is read. Memcached is based on a hashmap that stores key/value pairs. Its daemon (daemon) is written in C, but the client can write in any language and communicate with the daemon through the memcached protocol.

Memcached is a set of distributed cache system, originally Danga Interactive for LiveJournal development, but is currently used by many software (such as MediaWiki). This is a set of open source software that is released with BSD license authorization.

Memcached is a software developed by Brad Fitzpatric, a Danga Interactive company in LiveJournal. It has become an important factor in improving Web application extensibility in many services such as Mixi, Hatena, Facebook, Vox, and LiveJournal. Many Web applications save data to an RDBMS, where the application server reads the data and displays it in the browser. However, with the increase of data volume and the concentration of access, the burden of RDBMS, database response deterioration, site display delay and other significant impact.

This is the time to memcached. Memcached is a high-performance distributed memory cache server. The general purpose is to reduce the number of database accesses by caching database query results to improve the speed and scalability of dynamic Web applications.

The Memcached Daemon (daemon) is written in C, but the client can be written in any language and communicates with the daemon through the Memcached protocol. However, it does not provide redundancy (for example, copying its hashmap entries), and when a server S is stopped or crashed, all key/value pairs stored on s are lost.

The following is the installation method for the x86/x64 version of memcached under Windows system.

Run at the command prompt

Installation:

memcached-d Install

memcached-d start

Memcached-m 256m-d Start

net start "Memcached Server"

Unloading:

memcached-d stop

memcached-d Remove

SC delete "Memcached Server"

Basic Settings for memcached:

-P Listening Port

-L connected IP address, default is native

-D Start memcached service

-D Restart Restart memcached service

-D Stop|shutdown Close the running memcached service

-D Install memcached service

-d Uninstall Uninstall memcached service

-U Run as (only valid when running as root)

-m maximum memory usage, in megabytes. Default 64MB

-M running out of memory and returning an error instead of deleting an item

-c Maximum number of simultaneous connections, default is 1024

-F Block size growth factor, default is 1.25

-N Minimum allocated space, key+value+flags default is 48

-H Display Help

Add Name[key] 0[flag bit] 60[time] 5[put in how big data]

Set name 0 60 5 Update if available

Replace replaces the existing key

Append

Prepend additional Modifications

INCR Key Increase number

DECR Key Reduction number

Delete key

Flush_all All Empty

Stats Command Usage times

The basic concept of memcached


Memcached is an efficient, support distributed memory object caching system that can support putting various data into its managed memory [arrays, objects, basic data types]

Benefits of using memcached:

Access speed: Database < file < memory


Installation steps:

1. Download memcached software

2. Copy the memcached software to a directory, preferably in the development environment directory for easy Management

3. Installing memcached-d Install

4. Uninstall using memcached-d Uninstall

5. Start the memcached service

(1) Start the service directly through the interface

(2) Starting memcached-d start on the console

6. Check to see if the Memcached service started successfully. Default Port 11211


Basic commands for memcached (installation, uninstallation, startup, configuration related)

-P Listening Port

-L connected IP address, default is native

-D Start memcached service

-D Restart Restart memcached service

-D Stop|shutdown Close the running memcached service

-D Install memcached service

-d Uninstall Uninstall memcached service

-U Run as (only valid when running as root)

-m maximum memory usage, in MB. The default is 64MB, the maximum seems to be 2G

-M running out of memory and returning an error instead of deleting an item

-c Maximum number of simultaneous connections, default is 1024

-F Block size growth factor, default is 1.25

-N Minimum allocated space, key+value+flags default is 48

-H Display Help

Special Note: If your site needs to memcached more than 64M of memory should start like this

Memcached-m 256m-d Start

If greater than 256m, the unused cache is automatically deleted based on the LRU (Least recently used) algorithm

If you want to change a port: memcached-d-m30-l 127.0.0.1-p 9000-d start[linux Use]

Apche//iis

ftp

-Telnet

3306 MySQL

1521 Oracle

1433 SQL Server

8080 Tomcat


Usage method (CRUD)

Telnet-------->memecached Cache system

Program (1. Extended by Memcache. 2. Extended via memcached 3. Socket access)-------->memcached cache System

1. Connect to memcached:telnet 127.0.0.1 11211

2.add name 0 60 5 [description Add is the name of the instruction name is key (is stored in key/value form) 0 is the flag 60 means that the data is stored 60 seconds 5 indicates how big the data is placed]

3.get name[Get the value of name]

4.set Name 0 60 5[If name exists then update, does not exist add]

5. Remove: Delete key

6.replace replacement, error if key does not exist

7.append Append

8.prepend Add in front

Eg:add Name 0 60 5

Append name 0 60 3

Prepend Name 0 60 5

9.INCR added: incr key 2[for digital]

10.DECR reduction: DECR Key 3

11.flush_all All Empty

12.flush_all 900: Data cleared within 900 seconds of validity

13.stats: Show the number of command operations



memcached basic Commands (when memcached is started, for commands related to the management data of memcached and its own running state)


Setting up firewalls under Linux

Iptables-a INPUT-P protocol-S can access Ip-dport port-j ACCEPT


Summary

Small website, PV value is not big, do not need to use

Frequent changes, frequent queries, but not necessarily written to the database, suitable for use

Change frequently, but data needs to be put into storage, and data is very important, not suitable for use

Change infrequently, query frequently, regardless of into the storage, are more suitable for use



This article is from the "Inverse Day" blog, please be sure to keep this source http://xxzjzsj.blog.51cto.com/3052058/1629855

memcached Introduction, installation and basic use

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.