Memcached Quick Start

Source: Internet
Author: User
Memcached Quick Start what is memcached

Memcached is a high-performance distributed memory object Cache System for dynamic web applications to reduce database load. It caches data and objects in the memory to reduce the number of reads to the database, thus improving the speed of dynamic and database-driven websites.

Install Ubuntu
$ sudo apt-get install memcached$ ps aux | grep memcachedmemcache 26355  0.0  0.0 325400  1208 ?        Sl   16:30   0:00 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1
Source code
sudo apt-get install g++ make libevent-devcurl -O --location http://memcached.org/latestmv latest memcached-latest.tar.gztar vxzf memcached-latest.tar.gzcd memcached-*./configure && makesudo make install
Configuration
vim /etc/memcached.conf
  • -L 127.0.0.1 listener IP Address
  • -M 64: maximum memory allowed. The default value is 4 megabytes (MB)
Install Telnet through communication with memcached
sudo apt-get install telnet
Try
$ telnet localhost 11211Trying 127.0.0.1...Connected to localhost.Escape character is ‘^]‘.
Detailed ASCII (text) Protocol

Https://github.com/memcached/memcached/blob/master/doc/protocol.txt

Query Basic Information
statsSTAT pid 26355STAT uptime 457STAT time 1404290303STAT version 1.4.14STAT libevent 2.0.21-stableSTAT pointer_size 64STAT rusage_user 0.007959STAT rusage_system 0.007959STAT curr_connections 5STAT total_connections 6STAT connection_structures 6STAT reserved_fds 20STAT cmd_get 0STAT cmd_set 0STAT cmd_flush 0STAT cmd_touch 0STAT get_hits 0STAT get_misses 0STAT delete_misses 0STAT delete_hits 0STAT incr_misses 0STAT incr_hits 0STAT decr_misses 0STAT decr_hits 0STAT cas_misses 0STAT cas_hits 0STAT cas_badval 0STAT touch_hits 0STAT touch_misses 0STAT auth_cmds 0STAT auth_errors 0STAT bytes_read 7STAT bytes_written 0STAT limit_maxbytes 67108864STAT accepting_conns 1STAT listen_disabled_num 0STAT threads 4STAT conn_yields 0STAT hash_power_level 16STAT hash_bytes 524288STAT hash_is_expanding 0STAT expired_unfetched 0STAT evicted_unfetched 0STAT bytes 0STAT curr_items 0STAT total_items 0STAT evictions 0STAT reclaimed 0END
View configurations
stats settingsSTAT maxbytes 67108864STAT maxconns 1024STAT tcpport 11211STAT udpport 11211STAT inter 127.0.0.1STAT verbosity 0STAT oldest 0STAT evictions onSTAT domain_socket NULLSTAT umask 700STAT growth_factor 1.25STAT chunk_size 48STAT num_threads 4STAT num_threads_per_udp 4STAT stat_key_prefix :STAT detail_enabled noSTAT reqs_per_event 20STAT cas_enabled yesSTAT tcp_backlog 1024STAT binding_protocol auto-negotiateSTAT auth_enabled_sasl noSTAT item_size_max 1048576STAT maxconns_fast noSTAT hashpower_init 0STAT slab_reassign noSTAT slab_automove 0END
Save Value
set mykey 0 300 16I Love Memcached

Press enter.Stored

set mykey 0 300 16I Love MemcachedSTORED

Now we can useGetObtained Value

get mykeyVALUE mykey 0 16I Love MemcachedEND

SetFormat:

<command name> <key> <flags> <exptime> <bytes>
Set memcached startup
$ /etc/init.d/memcached status * memcached is running

Disable

sudo update-rc.d memcached disable

Enable

sudo update-rc.d memcached enable

Confirm the default running level:

sudo update-rc.d memcached defaults
Distributed deployment
memcached -p 3030memcached -p 3031import pylibmcmc = pylibmc.Client(["127.0.0.1:3030", "127.0.0.1:3031"], binary=True,behaviors={"tcp_nodelay": True, "ketama": True})mc["ahmed"] = "Hello World"mc["tek"] = "Hello World"
  • Binary = true: Binary protocol, non-ASCII protocol
  • Behaviors = {"tcp_nodelay": True, "ketama": true}: "ketama" = true means that the MD5 hash algorithm is used to distribute keys.

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.