SlideShare a Scribd company logo
1 of 28
Aniruddha Chakrabarti
AVP and Solution Lead, Digital Practice, Mphasis
ani.c@outlook.com | Linkedin.com/in/aniruddhac | slideshare.net/aniruddha.chakrabarti/ | Twitter - anchakra
Overview of memcached Distributed Cache
Agenda
• What is memcached (and what it’s not)
• Popularity of memcached, who uses memcached, history of memcached
• memcached vs. MemcacheDB
• Memcached operations
• Store data (set)
• Update data (replace, append, prepend)
• Retrieve data (get)
• Remove date (delete)
• Clear data
• Increment & Necrement numeric value
• Clear all data
• Server statistics
• Resources
What is memcached
• High-performance, distributed in-memory object caching system
• Free & open source (licensed under BSD license)
• Memcached in completely in memory, it cannot persist any data, and so it’s mostly
suitable for caching.
• For persistent storage memcachedb could be used, which is a different product.
• memcached is an in-memory key-value store for small chunks of arbitrary data (strings,
objects) from results of database calls, API calls, or page rendering.
• Generic in nature, but mostly intended for use in speeding up dynamic web applications
by alleviating database load.
• Its simple design promotes quick deployment, ease of development, and solves many
problems facing large data caches.
• Memcahed runs on Linux, OSX and Windows. memcached API is available for most
popular languages.
Caching strategies
• Read-through caching
• Client tier requests Application tier for some data
• Application tier checks if the data already exist in Cache tier (memcached)
• If data exists, then it’s returned directly from Cache tier (memcached) saving
database round trip and load on database
• If data does not exist, then it’s retrieved from database and returned to app tier. The
data is added to cache tier so that subsequent requested could be served from cache.
• Write-through caching
• Data is written to memcached, data is not written directly to database (as done in
read-through approach). A separate process reads the stored data from memcached
and writes to the database
Noteable memcached users
• LiveJournal
• Wikipedia
• Flickr
• Bebo
• Twitter
• Typepad
• Yellowbot
• Youtube
• WordPress.com
• Craigslist
• Mixi
Popularity of memcached
• memcahed is ranked 22rd among all
Databases products including
RDBMS and NoSQL
• memcahed is the 2nd popular in
memory Key Value store after Redis
• It seems recently redis has become
more popular than memcached
memcached history
• Memcached was first developed by Brad Fitzpatrick for the website
LiveJournal, on May 22, 2003 at Danga Interactive. It reduced the database
load for the extremely busy web site LiveJournal.com, which was at the
time handling over 20 million dynamic page views per day for 1 million
users.
• Solved for LiveJournal.com the problem that many other sites also have —
how to reduce read access to the database.
• It was originally written in Perl, then later rewritten in C by Anatoly
Vorobey, then employed by LiveJournal.
memcached vs MemcacheDB
• memcached is a distributed in memory key value cache.
• MemcacheDB is a distributed key-value storage system designed for
persistent. It is NOT a cache solution, but a persistent storage engine for
fast and reliable key-value based object storage and retrieval.
Installing and running memcached
Download memcached from http://memcached.org/downloads.
Unzip the .gz file to any folder
memcached Server:
• Run memcached.exe
memcached Client:
• Connect to memcached via telnet
C:>telnet 127.0.0.1 11211
11211 is the default port
to which memcached server listens
Set Data
• set command is used to set a value to key; if the key does not exist, a new key is created
and value is assigned to that key.
set key flags exptime bytes [noreply]
value
• key - It is the name of the unique key by which data is accessed.
• flags - It is the 32-bit unsigned integer that the server stores with the data provided by the user,
and returns along with the data when the item is retrieved.
• exptime - It is the expiration time (seconds) of data stored in cache. A 0 value means "never
expire", i.e. it should not be removed from the cache unless required. If the exptime is more than
30 days then Memcached interprets it as UNIX timestamp for expiration.
• bytes - This is the length of the data in bytes that needs to be stored in Memcached.
• noreply (optional) - This parameter informs the server not to send any reply.
• value - It is the data that needs to be stored. The data needs to be given on the new line after
executing the command with the above options.
Set Data - example
set key flags exptime bytes [noreply]
Value
set tutorial 0 0 18
memcached tutorial
STORED
set city 0 900 9
bangalore
STORED
Flags Expiry time (in seconds)
Length of data in bytes to be stored
Value to be stored
Key
Flags
Expiry time (in seconds)
0 indicates no expiry
Length of data in bytes to be stored
Value to be stored
Key
• key - It is the name of the unique key by
which data is accessed.
• flags - It is the 32-bit unsigned integer
that the server stores with the data
provided by the user, and returns along
with the data when the item is retrieved.
• exptime - It is the expiration time
(seconds) of data stored in cache. A 0
value means "never expire", i.e. it should
not be removed from the cache unless
required. If the exptime is more than 30
days then Memcached interprets it as
UNIX timestamp for expiration.
• bytes - This is the length of the data in
bytes that needs to be stored in
Memcached.
• noreply (optional) - This parameter
informs the server not to send any reply.
• value - It is the data that needs to be
stored. The data needs to be given on the
new line after executing the command
with the above options.
Get Data - example
get key [noreply]
set city 0 900 9
bangalore
STORED
set tutorial 0 0 18
memcached tutorial
STORED
get city
VALUE city 0 9
bangalore
END
get tutorial
VALUE tutorial 0 9
memcached tutorial
END
get key1 key2 [noreply]
get city tutorial
VALUE city 0 9
bangalore
VALUE tutorial 0 11
memcached t
END
Append Data
• append command is used to add data in an existing key. This data is added at the
end of the previous value.
append key flags exptime bytes [noreply]
value
append city 0 0 8
,india
STORED
get city
VALUE city 0 17
bangalore,india
Prepend Data
• prepend command is used to add data in an existing key. This data is added before the
existing data of the key.
prepend key flags exptime bytes [noreply]
value
get city
VALUE city 0 17
bangalore,india
prepend city 0 0 13
whitefield,
STORED
get city
VALUE city 0 30
whitefield,bangalore,india
END
Replace Data
• replace command is used to replace the value of an existing key. If the key does not
exist, then it gives the output NOT_STORED.
prepend key flags exptime bytes [noreply]
value
get city
VALUE city 0 30
whitefield,bangalore,india
replace city 0 0 7
kolkata
STORED
get city
VALUE city 0 7
kolkata
Delete Data
delete key [noreply]
Output:
• DELETED indicates successful deletion.
• ERROR indicates error while deleting data or wrong syntax.
• NOT_FOUND indicates that the key does not exist in the Memcached server.
delete city
DELETED
Incr and Decr
• incr and decr commands are used to increment or decrement the numeric value of an existing key.
If the key is not found, then it returns NOT_FOUND. If the key is not numeric, then it
returns CLIENT_ERROR cannot increment or decrement non-numeric value. Otherwise, ERROR is
returned.
incr key increment_value
set ctr 0 0 1
1
STORED
incr ctr 1
2
incr ctr 5
7
decr key decrement_value
decr ctr 1
6
incr ctr 3
3
Server Stats
• stats command is used to return server statistics such as PID, version, connections, etc.
stats
STAT pid 7484
STAT uptime 17901
STAT time 1442771796
STAT version 1.4.5_4_gaa7839e
STAT pointer_size 64
STAT curr_connections 10
STAT total_connections 11
STAT connection_structures 11
STAT cmd_get 24
STAT cmd_set 13
STAT cmd_flush 0
STAT get_hits 18
...
Clear Data
• flush_all command is used to delete all data (key-value pairs) from the Memcached server. It
accepts an optional parameter called time, that sets a time after which the Memcached data is to be
cleared.
flush_all
OK
get city tutorial
END
Using memcached from node
https://github.com/3rd-Eden/memcached
Node driver Installation – npm install memcached
var Memcached = require('memcached');
// first parameter is server location which is mentioned as host:port
// Here host is 127.0.0.1 or localhost & port is 11211 which is the default port for memcached
var memcached = new Memcached("127.0.0.1:11211");
// Other options could be passed as an object as second parameter
//var options = {retries:10,retry:10000,remove:true,failOverServers:['192.168.0.103:11211']};
//var memcached = new Memcached("127.0.0.1:11211", options);
Using get and set from node
memcached.get - Get the value for the given key in Memcached.
memcached.set - Stores a new value in Memcached.
var key = 'city', value = 'Bangalore';
var lifetime = 300; // lifetime in seconds
memcached.set(key, value, lifetime, function(error){
if (!error){
console.log('data added to cache');
memcached.get(key, function(error, data){
console.log(data);
});
}
});
Using add from node (error)
memcached.add - Add the value, only if it's not in memcached already.
var key = 'city', value = 'Bangalore', lifetime = 0; // lifetime in seconds, 0 means no expiry
memcached.set(key, value, lifetime, function(error){
if (!error){
console.log('data added to cache');
memcached.get(key, function(error, data){
console.log(data);
});
memcached.add(key, "Den Haag", lifetime, function (error){
if (error){
console.log(error);
}
});
}
});
Using add from node (success)
memcached.add - Add the value, only if it's not in memcached already.
memcached.add('new_city', 'Den Haag', 300, function (error){
if (error){
console.log(error);
}
else{
memcached.get('new_city', function(error, data){
console.log(data);
});
}
});
Using prepend and append from node
memcached.append - Add the given value to the start of an existing item
memcached.prepend - Add the given value to the end of an existing item
memcached.prepend(key, "Whitefield, ", function(error){
if (!error){
memcached.append(key, ", Karnataka, IN", function(error){
memcached.get(key, function (error, data){
if(!error){
console.log(data);
// displays Whitefield, Bangalore, Karnataka, IN
}
});
});
}
})
Using replace and del from node
memcached.replace - Replaces the existing value of a key in memcached
memcached.del - Removes the key from memcached
memcached.replace('city','Minneapolis, MN', 300, function(err){});
memcached.get('city', function(err, data){
console.log(data); // displays Minneapolis, MN
});
memcached.del('city',function(err){
if(!err){
console.log('del success');
}
});
Using getMulti from node
memcached.getMulti - Retrieves a bunch of values from multiple keys
memcached.set('city1','New Delhi',0, function(error){});
memcached.set('city2','Kolkata',0, function(error){});
memcached.set('city3','Amsterdam',0, function(error){});
memcached.getMulti(['city1','city2','city3'], function (error, data){
if (!error){
console.log(data.city1);
console.log(data.city2);
console.log(data.city3);
}
})
Using incr and decr from node
memcached.incr - Increment a given key by the specified value
memcached.incr - Decrement a given key by the specified value
memcached.set('ctr', 10, 0, function(error){});
memcached.incr('ctr', 5, function(error){});
memcached.get('ctr', function(error, data){
console.log(data); // 15
});
memcached.decr('ctr', 10, function(error){});
memcached.get('ctr', function(error, data){
console.log(data); // 5
});
Resources
• http://memcached.org/
• http://www.tutorialspoint.com/memcached/
• https://code.google.com/p/memcached/wiki/NewStart

More Related Content

What's hot

Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in ScalaAlex Payne
 
Efficient in situ processing of various storage types on apache tajo
Efficient in situ processing of various storage types on apache tajoEfficient in situ processing of various storage types on apache tajo
Efficient in situ processing of various storage types on apache tajoHyunsik Choi
 
Data analysis scala_spark
Data analysis scala_sparkData analysis scala_spark
Data analysis scala_sparkYiguang Hu
 
Key-Value-Stores -- The Key to Scaling?
Key-Value-Stores -- The Key to Scaling?Key-Value-Stores -- The Key to Scaling?
Key-Value-Stores -- The Key to Scaling?Tim Lossen
 
Big data, just an introduction to Hadoop and Scripting Languages
Big data, just an introduction to Hadoop and Scripting LanguagesBig data, just an introduction to Hadoop and Scripting Languages
Big data, just an introduction to Hadoop and Scripting LanguagesCorley S.r.l.
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redisjimbojsb
 
Attack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaAttack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaPrajal Kulkarni
 
Getting started with Spark & Cassandra by Jon Haddad of Datastax
Getting started with Spark & Cassandra by Jon Haddad of DatastaxGetting started with Spark & Cassandra by Jon Haddad of Datastax
Getting started with Spark & Cassandra by Jon Haddad of DatastaxData Con LA
 
Kindling: Getting Started with Spark and Cassandra
Kindling: Getting Started with Spark and CassandraKindling: Getting Started with Spark and Cassandra
Kindling: Getting Started with Spark and CassandraDataStax Academy
 
Cassandra Summit 2015: Intro to DSE Search
Cassandra Summit 2015: Intro to DSE SearchCassandra Summit 2015: Intro to DSE Search
Cassandra Summit 2015: Intro to DSE SearchCaleb Rackliffe
 
11. From Hadoop to Spark 2/2
11. From Hadoop to Spark 2/211. From Hadoop to Spark 2/2
11. From Hadoop to Spark 2/2Fabio Fumarola
 
Bay area Cassandra Meetup 2011
Bay area Cassandra Meetup 2011Bay area Cassandra Meetup 2011
Bay area Cassandra Meetup 2011mubarakss
 
DTCC '14 Spark Runtime Internals
DTCC '14 Spark Runtime InternalsDTCC '14 Spark Runtime Internals
DTCC '14 Spark Runtime InternalsCheng Lian
 
Learning Cassandra
Learning CassandraLearning Cassandra
Learning CassandraDave Gardner
 
Cassandra vs. Redis
Cassandra vs. RedisCassandra vs. Redis
Cassandra vs. RedisTim Lossen
 
How you can contribute to Apache Cassandra
How you can contribute to Apache CassandraHow you can contribute to Apache Cassandra
How you can contribute to Apache CassandraYuki Morishita
 
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# DriverCassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# DriverDataStax Academy
 
MongoFr : MongoDB as a log Collector
MongoFr : MongoDB as a log CollectorMongoFr : MongoDB as a log Collector
MongoFr : MongoDB as a log CollectorPierre Baillet
 
Developing and Deploying Apps with the Postgres FDW
Developing and Deploying Apps with the Postgres FDWDeveloping and Deploying Apps with the Postgres FDW
Developing and Deploying Apps with the Postgres FDWJonathan Katz
 

What's hot (20)

Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in Scala
 
HiveServer2
HiveServer2HiveServer2
HiveServer2
 
Efficient in situ processing of various storage types on apache tajo
Efficient in situ processing of various storage types on apache tajoEfficient in situ processing of various storage types on apache tajo
Efficient in situ processing of various storage types on apache tajo
 
Data analysis scala_spark
Data analysis scala_sparkData analysis scala_spark
Data analysis scala_spark
 
Key-Value-Stores -- The Key to Scaling?
Key-Value-Stores -- The Key to Scaling?Key-Value-Stores -- The Key to Scaling?
Key-Value-Stores -- The Key to Scaling?
 
Big data, just an introduction to Hadoop and Scripting Languages
Big data, just an introduction to Hadoop and Scripting LanguagesBig data, just an introduction to Hadoop and Scripting Languages
Big data, just an introduction to Hadoop and Scripting Languages
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Attack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaAttack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and Kibana
 
Getting started with Spark & Cassandra by Jon Haddad of Datastax
Getting started with Spark & Cassandra by Jon Haddad of DatastaxGetting started with Spark & Cassandra by Jon Haddad of Datastax
Getting started with Spark & Cassandra by Jon Haddad of Datastax
 
Kindling: Getting Started with Spark and Cassandra
Kindling: Getting Started with Spark and CassandraKindling: Getting Started with Spark and Cassandra
Kindling: Getting Started with Spark and Cassandra
 
Cassandra Summit 2015: Intro to DSE Search
Cassandra Summit 2015: Intro to DSE SearchCassandra Summit 2015: Intro to DSE Search
Cassandra Summit 2015: Intro to DSE Search
 
11. From Hadoop to Spark 2/2
11. From Hadoop to Spark 2/211. From Hadoop to Spark 2/2
11. From Hadoop to Spark 2/2
 
Bay area Cassandra Meetup 2011
Bay area Cassandra Meetup 2011Bay area Cassandra Meetup 2011
Bay area Cassandra Meetup 2011
 
DTCC '14 Spark Runtime Internals
DTCC '14 Spark Runtime InternalsDTCC '14 Spark Runtime Internals
DTCC '14 Spark Runtime Internals
 
Learning Cassandra
Learning CassandraLearning Cassandra
Learning Cassandra
 
Cassandra vs. Redis
Cassandra vs. RedisCassandra vs. Redis
Cassandra vs. Redis
 
How you can contribute to Apache Cassandra
How you can contribute to Apache CassandraHow you can contribute to Apache Cassandra
How you can contribute to Apache Cassandra
 
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# DriverCassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
 
MongoFr : MongoDB as a log Collector
MongoFr : MongoDB as a log CollectorMongoFr : MongoDB as a log Collector
MongoFr : MongoDB as a log Collector
 
Developing and Deploying Apps with the Postgres FDW
Developing and Deploying Apps with the Postgres FDWDeveloping and Deploying Apps with the Postgres FDW
Developing and Deploying Apps with the Postgres FDW
 

Viewers also liked

Viewers also liked (19)

Groovy Programming Language
Groovy Programming LanguageGroovy Programming Language
Groovy Programming Language
 
WPF Deep Dive
WPF Deep DiveWPF Deep Dive
WPF Deep Dive
 
Building RIA Apps with Silverlight
Building RIA Apps with SilverlightBuilding RIA Apps with Silverlight
Building RIA Apps with Silverlight
 
pebble - Building apps on pebble
pebble - Building apps on pebblepebble - Building apps on pebble
pebble - Building apps on pebble
 
Distributed Applications with Perl & Gearman
Distributed Applications with Perl & GearmanDistributed Applications with Perl & Gearman
Distributed Applications with Perl & Gearman
 
Gearman and Perl
Gearman and PerlGearman and Perl
Gearman and Perl
 
Gearman for MySQL
Gearman for MySQLGearman for MySQL
Gearman for MySQL
 
Overview of CoffeeScript
Overview of CoffeeScriptOverview of CoffeeScript
Overview of CoffeeScript
 
Distributed Queue System using Gearman
Distributed Queue System using GearmanDistributed Queue System using Gearman
Distributed Queue System using Gearman
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
Why Memcached?
Why Memcached?Why Memcached?
Why Memcached?
 
Agile Practices - eXtreme Programming
Agile Practices - eXtreme ProgrammingAgile Practices - eXtreme Programming
Agile Practices - eXtreme Programming
 
Wideband Delphi Estimation
Wideband Delphi EstimationWideband Delphi Estimation
Wideband Delphi Estimation
 
Gearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleGearman: A Job Server made for Scale
Gearman: A Job Server made for Scale
 
CoAP - Web Protocol for IoT
CoAP - Web Protocol for IoTCoAP - Web Protocol for IoT
CoAP - Web Protocol for IoT
 
Lisp
LispLisp
Lisp
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 
Amazon alexa - building custom skills
Amazon alexa - building custom skillsAmazon alexa - building custom skills
Amazon alexa - building custom skills
 

Similar to memcached Distributed Cache

Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetAchieve Internet
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetAchieve Internet
 
iland Internet Solutions: Leveraging Cassandra for real-time multi-datacenter...
iland Internet Solutions: Leveraging Cassandra for real-time multi-datacenter...iland Internet Solutions: Leveraging Cassandra for real-time multi-datacenter...
iland Internet Solutions: Leveraging Cassandra for real-time multi-datacenter...DataStax Academy
 
Leveraging Cassandra for real-time multi-datacenter public cloud analytics
Leveraging Cassandra for real-time multi-datacenter public cloud analyticsLeveraging Cassandra for real-time multi-datacenter public cloud analytics
Leveraging Cassandra for real-time multi-datacenter public cloud analyticsJulien Anguenot
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsConcentric Sky
 
Relational cloud, A Database-as-a-Service for the Cloud
Relational cloud, A Database-as-a-Service for the CloudRelational cloud, A Database-as-a-Service for the Cloud
Relational cloud, A Database-as-a-Service for the CloudHossein Riasati
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Lonestar php scalingmagento
Lonestar php scalingmagentoLonestar php scalingmagento
Lonestar php scalingmagentoMathew Beane
 
Membase Intro from Membase Meetup San Francisco
Membase Intro from Membase Meetup San FranciscoMembase Intro from Membase Meetup San Francisco
Membase Intro from Membase Meetup San FranciscoMembase
 
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019Dave Stokes
 
Memcached Presentation
Memcached PresentationMemcached Presentation
Memcached PresentationAsif Ali
 
C* Summit 2013: Cassandra at eBay Scale by Feng Qu and Anurag Jambhekar
C* Summit 2013: Cassandra at eBay Scale by Feng Qu and Anurag JambhekarC* Summit 2013: Cassandra at eBay Scale by Feng Qu and Anurag Jambhekar
C* Summit 2013: Cassandra at eBay Scale by Feng Qu and Anurag JambhekarDataStax Academy
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performanceEngine Yard
 
7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth7. Key-Value Databases: In Depth
7. Key-Value Databases: In DepthFabio Fumarola
 
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]Speedment, Inc.
 

Similar to memcached Distributed Cache (20)

Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
iland Internet Solutions: Leveraging Cassandra for real-time multi-datacenter...
iland Internet Solutions: Leveraging Cassandra for real-time multi-datacenter...iland Internet Solutions: Leveraging Cassandra for real-time multi-datacenter...
iland Internet Solutions: Leveraging Cassandra for real-time multi-datacenter...
 
Leveraging Cassandra for real-time multi-datacenter public cloud analytics
Leveraging Cassandra for real-time multi-datacenter public cloud analyticsLeveraging Cassandra for real-time multi-datacenter public cloud analytics
Leveraging Cassandra for real-time multi-datacenter public cloud analytics
 
MySQL vs MonetDB Bencharmarks
MySQL vs MonetDB BencharmarksMySQL vs MonetDB Bencharmarks
MySQL vs MonetDB Bencharmarks
 
Memcached
MemcachedMemcached
Memcached
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
Relational cloud, A Database-as-a-Service for the Cloud
Relational cloud, A Database-as-a-Service for the CloudRelational cloud, A Database-as-a-Service for the Cloud
Relational cloud, A Database-as-a-Service for the Cloud
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Lonestar php scalingmagento
Lonestar php scalingmagentoLonestar php scalingmagento
Lonestar php scalingmagento
 
Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
 
Membase Intro from Membase Meetup San Francisco
Membase Intro from Membase Meetup San FranciscoMembase Intro from Membase Meetup San Francisco
Membase Intro from Membase Meetup San Francisco
 
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
 
No sql presentation
No sql presentationNo sql presentation
No sql presentation
 
Memcached Presentation
Memcached PresentationMemcached Presentation
Memcached Presentation
 
C* Summit 2013: Cassandra at eBay Scale by Feng Qu and Anurag Jambhekar
C* Summit 2013: Cassandra at eBay Scale by Feng Qu and Anurag JambhekarC* Summit 2013: Cassandra at eBay Scale by Feng Qu and Anurag Jambhekar
C* Summit 2013: Cassandra at eBay Scale by Feng Qu and Anurag Jambhekar
 
Typesafe spark- Zalando meetup
Typesafe spark- Zalando meetupTypesafe spark- Zalando meetup
Typesafe spark- Zalando meetup
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performance
 
7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth
 
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
 

More from Aniruddha Chakrabarti

Thomas Cook and Accenture expand relationship with 10 year technology consult...
Thomas Cook and Accenture expand relationship with 10 year technology consult...Thomas Cook and Accenture expand relationship with 10 year technology consult...
Thomas Cook and Accenture expand relationship with 10 year technology consult...Aniruddha Chakrabarti
 
NLP using JavaScript Natural Library
NLP using JavaScript Natural LibraryNLP using JavaScript Natural Library
NLP using JavaScript Natural LibraryAniruddha Chakrabarti
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageAniruddha Chakrabarti
 
Using Node-RED for building IoT workflows
Using Node-RED for building IoT workflowsUsing Node-RED for building IoT workflows
Using Node-RED for building IoT workflowsAniruddha Chakrabarti
 
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...Aniruddha Chakrabarti
 
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)Aniruddha Chakrabarti
 
Future of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows PlatformsFuture of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows PlatformsAniruddha Chakrabarti
 
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoTMphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoTAniruddha Chakrabarti
 

More from Aniruddha Chakrabarti (14)

Pinecone Vector Database.pdf
Pinecone Vector Database.pdfPinecone Vector Database.pdf
Pinecone Vector Database.pdf
 
Mphasis-Annual-Report-2018.pdf
Mphasis-Annual-Report-2018.pdfMphasis-Annual-Report-2018.pdf
Mphasis-Annual-Report-2018.pdf
 
Thomas Cook and Accenture expand relationship with 10 year technology consult...
Thomas Cook and Accenture expand relationship with 10 year technology consult...Thomas Cook and Accenture expand relationship with 10 year technology consult...
Thomas Cook and Accenture expand relationship with 10 year technology consult...
 
NLP using JavaScript Natural Library
NLP using JavaScript Natural LibraryNLP using JavaScript Natural Library
NLP using JavaScript Natural Library
 
Dart programming language
Dart programming languageDart programming language
Dart programming language
 
Third era of computing
Third era of computingThird era of computing
Third era of computing
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
Using Node-RED for building IoT workflows
Using Node-RED for building IoT workflowsUsing Node-RED for building IoT workflows
Using Node-RED for building IoT workflows
 
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
 
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
 
Future of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows PlatformsFuture of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows Platforms
 
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoTMphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
 
MS-Misys Opics Plus.PDF
MS-Misys Opics Plus.PDFMS-Misys Opics Plus.PDF
MS-Misys Opics Plus.PDF
 
Misys Opics Plus Solution Brief
Misys Opics Plus Solution BriefMisys Opics Plus Solution Brief
Misys Opics Plus Solution Brief
 

Recently uploaded

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 

Recently uploaded (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 

memcached Distributed Cache

  • 1. Aniruddha Chakrabarti AVP and Solution Lead, Digital Practice, Mphasis ani.c@outlook.com | Linkedin.com/in/aniruddhac | slideshare.net/aniruddha.chakrabarti/ | Twitter - anchakra Overview of memcached Distributed Cache
  • 2. Agenda • What is memcached (and what it’s not) • Popularity of memcached, who uses memcached, history of memcached • memcached vs. MemcacheDB • Memcached operations • Store data (set) • Update data (replace, append, prepend) • Retrieve data (get) • Remove date (delete) • Clear data • Increment & Necrement numeric value • Clear all data • Server statistics • Resources
  • 3. What is memcached • High-performance, distributed in-memory object caching system • Free & open source (licensed under BSD license) • Memcached in completely in memory, it cannot persist any data, and so it’s mostly suitable for caching. • For persistent storage memcachedb could be used, which is a different product. • memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering. • Generic in nature, but mostly intended for use in speeding up dynamic web applications by alleviating database load. • Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. • Memcahed runs on Linux, OSX and Windows. memcached API is available for most popular languages.
  • 4. Caching strategies • Read-through caching • Client tier requests Application tier for some data • Application tier checks if the data already exist in Cache tier (memcached) • If data exists, then it’s returned directly from Cache tier (memcached) saving database round trip and load on database • If data does not exist, then it’s retrieved from database and returned to app tier. The data is added to cache tier so that subsequent requested could be served from cache. • Write-through caching • Data is written to memcached, data is not written directly to database (as done in read-through approach). A separate process reads the stored data from memcached and writes to the database
  • 5. Noteable memcached users • LiveJournal • Wikipedia • Flickr • Bebo • Twitter • Typepad • Yellowbot • Youtube • WordPress.com • Craigslist • Mixi
  • 6. Popularity of memcached • memcahed is ranked 22rd among all Databases products including RDBMS and NoSQL • memcahed is the 2nd popular in memory Key Value store after Redis • It seems recently redis has become more popular than memcached
  • 7. memcached history • Memcached was first developed by Brad Fitzpatrick for the website LiveJournal, on May 22, 2003 at Danga Interactive. It reduced the database load for the extremely busy web site LiveJournal.com, which was at the time handling over 20 million dynamic page views per day for 1 million users. • Solved for LiveJournal.com the problem that many other sites also have — how to reduce read access to the database. • It was originally written in Perl, then later rewritten in C by Anatoly Vorobey, then employed by LiveJournal.
  • 8. memcached vs MemcacheDB • memcached is a distributed in memory key value cache. • MemcacheDB is a distributed key-value storage system designed for persistent. It is NOT a cache solution, but a persistent storage engine for fast and reliable key-value based object storage and retrieval.
  • 9. Installing and running memcached Download memcached from http://memcached.org/downloads. Unzip the .gz file to any folder memcached Server: • Run memcached.exe memcached Client: • Connect to memcached via telnet C:>telnet 127.0.0.1 11211 11211 is the default port to which memcached server listens
  • 10. Set Data • set command is used to set a value to key; if the key does not exist, a new key is created and value is assigned to that key. set key flags exptime bytes [noreply] value • key - It is the name of the unique key by which data is accessed. • flags - It is the 32-bit unsigned integer that the server stores with the data provided by the user, and returns along with the data when the item is retrieved. • exptime - It is the expiration time (seconds) of data stored in cache. A 0 value means "never expire", i.e. it should not be removed from the cache unless required. If the exptime is more than 30 days then Memcached interprets it as UNIX timestamp for expiration. • bytes - This is the length of the data in bytes that needs to be stored in Memcached. • noreply (optional) - This parameter informs the server not to send any reply. • value - It is the data that needs to be stored. The data needs to be given on the new line after executing the command with the above options.
  • 11. Set Data - example set key flags exptime bytes [noreply] Value set tutorial 0 0 18 memcached tutorial STORED set city 0 900 9 bangalore STORED Flags Expiry time (in seconds) Length of data in bytes to be stored Value to be stored Key Flags Expiry time (in seconds) 0 indicates no expiry Length of data in bytes to be stored Value to be stored Key • key - It is the name of the unique key by which data is accessed. • flags - It is the 32-bit unsigned integer that the server stores with the data provided by the user, and returns along with the data when the item is retrieved. • exptime - It is the expiration time (seconds) of data stored in cache. A 0 value means "never expire", i.e. it should not be removed from the cache unless required. If the exptime is more than 30 days then Memcached interprets it as UNIX timestamp for expiration. • bytes - This is the length of the data in bytes that needs to be stored in Memcached. • noreply (optional) - This parameter informs the server not to send any reply. • value - It is the data that needs to be stored. The data needs to be given on the new line after executing the command with the above options.
  • 12. Get Data - example get key [noreply] set city 0 900 9 bangalore STORED set tutorial 0 0 18 memcached tutorial STORED get city VALUE city 0 9 bangalore END get tutorial VALUE tutorial 0 9 memcached tutorial END get key1 key2 [noreply] get city tutorial VALUE city 0 9 bangalore VALUE tutorial 0 11 memcached t END
  • 13. Append Data • append command is used to add data in an existing key. This data is added at the end of the previous value. append key flags exptime bytes [noreply] value append city 0 0 8 ,india STORED get city VALUE city 0 17 bangalore,india
  • 14. Prepend Data • prepend command is used to add data in an existing key. This data is added before the existing data of the key. prepend key flags exptime bytes [noreply] value get city VALUE city 0 17 bangalore,india prepend city 0 0 13 whitefield, STORED get city VALUE city 0 30 whitefield,bangalore,india END
  • 15. Replace Data • replace command is used to replace the value of an existing key. If the key does not exist, then it gives the output NOT_STORED. prepend key flags exptime bytes [noreply] value get city VALUE city 0 30 whitefield,bangalore,india replace city 0 0 7 kolkata STORED get city VALUE city 0 7 kolkata
  • 16. Delete Data delete key [noreply] Output: • DELETED indicates successful deletion. • ERROR indicates error while deleting data or wrong syntax. • NOT_FOUND indicates that the key does not exist in the Memcached server. delete city DELETED
  • 17. Incr and Decr • incr and decr commands are used to increment or decrement the numeric value of an existing key. If the key is not found, then it returns NOT_FOUND. If the key is not numeric, then it returns CLIENT_ERROR cannot increment or decrement non-numeric value. Otherwise, ERROR is returned. incr key increment_value set ctr 0 0 1 1 STORED incr ctr 1 2 incr ctr 5 7 decr key decrement_value decr ctr 1 6 incr ctr 3 3
  • 18. Server Stats • stats command is used to return server statistics such as PID, version, connections, etc. stats STAT pid 7484 STAT uptime 17901 STAT time 1442771796 STAT version 1.4.5_4_gaa7839e STAT pointer_size 64 STAT curr_connections 10 STAT total_connections 11 STAT connection_structures 11 STAT cmd_get 24 STAT cmd_set 13 STAT cmd_flush 0 STAT get_hits 18 ...
  • 19. Clear Data • flush_all command is used to delete all data (key-value pairs) from the Memcached server. It accepts an optional parameter called time, that sets a time after which the Memcached data is to be cleared. flush_all OK get city tutorial END
  • 20. Using memcached from node https://github.com/3rd-Eden/memcached Node driver Installation – npm install memcached var Memcached = require('memcached'); // first parameter is server location which is mentioned as host:port // Here host is 127.0.0.1 or localhost & port is 11211 which is the default port for memcached var memcached = new Memcached("127.0.0.1:11211"); // Other options could be passed as an object as second parameter //var options = {retries:10,retry:10000,remove:true,failOverServers:['192.168.0.103:11211']}; //var memcached = new Memcached("127.0.0.1:11211", options);
  • 21. Using get and set from node memcached.get - Get the value for the given key in Memcached. memcached.set - Stores a new value in Memcached. var key = 'city', value = 'Bangalore'; var lifetime = 300; // lifetime in seconds memcached.set(key, value, lifetime, function(error){ if (!error){ console.log('data added to cache'); memcached.get(key, function(error, data){ console.log(data); }); } });
  • 22. Using add from node (error) memcached.add - Add the value, only if it's not in memcached already. var key = 'city', value = 'Bangalore', lifetime = 0; // lifetime in seconds, 0 means no expiry memcached.set(key, value, lifetime, function(error){ if (!error){ console.log('data added to cache'); memcached.get(key, function(error, data){ console.log(data); }); memcached.add(key, "Den Haag", lifetime, function (error){ if (error){ console.log(error); } }); } });
  • 23. Using add from node (success) memcached.add - Add the value, only if it's not in memcached already. memcached.add('new_city', 'Den Haag', 300, function (error){ if (error){ console.log(error); } else{ memcached.get('new_city', function(error, data){ console.log(data); }); } });
  • 24. Using prepend and append from node memcached.append - Add the given value to the start of an existing item memcached.prepend - Add the given value to the end of an existing item memcached.prepend(key, "Whitefield, ", function(error){ if (!error){ memcached.append(key, ", Karnataka, IN", function(error){ memcached.get(key, function (error, data){ if(!error){ console.log(data); // displays Whitefield, Bangalore, Karnataka, IN } }); }); } })
  • 25. Using replace and del from node memcached.replace - Replaces the existing value of a key in memcached memcached.del - Removes the key from memcached memcached.replace('city','Minneapolis, MN', 300, function(err){}); memcached.get('city', function(err, data){ console.log(data); // displays Minneapolis, MN }); memcached.del('city',function(err){ if(!err){ console.log('del success'); } });
  • 26. Using getMulti from node memcached.getMulti - Retrieves a bunch of values from multiple keys memcached.set('city1','New Delhi',0, function(error){}); memcached.set('city2','Kolkata',0, function(error){}); memcached.set('city3','Amsterdam',0, function(error){}); memcached.getMulti(['city1','city2','city3'], function (error, data){ if (!error){ console.log(data.city1); console.log(data.city2); console.log(data.city3); } })
  • 27. Using incr and decr from node memcached.incr - Increment a given key by the specified value memcached.incr - Decrement a given key by the specified value memcached.set('ctr', 10, 0, function(error){}); memcached.incr('ctr', 5, function(error){}); memcached.get('ctr', function(error, data){ console.log(data); // 15 }); memcached.decr('ctr', 10, function(error){}); memcached.get('ctr', function(error, data){ console.log(data); // 5 });