Memcache | Memcached |
---|---|
Memcache module provides handy procedural and object-oriented interface to Memcached. | Memcached is a high-performance, distributed memory object caching system. |
Memcache is an extension that allows you to work through handy object-oriented (OOP's) and procedural interfaces. | Memcached is an extension that uses the libMemcached library to provide API for communicating with Memcached servers. |
The Memcache module provides a session handler (Memcache). | The Memcached provides a session handler (Memcached). |
It is designed to reduce database load in dynamic web applications. | It is used to increase the dynamic web applications by reducing database load. It is the latest API. |
$telnet HOST PORT ?
$telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
// store data and get that data from server
set javatpoint 0 900 9
memcached
STORED
get javatpoint
VALUE javatpoint 0 9
memcached
END ?
set key flags exptime bytes [noreply]
value ?
set javatpoint 0 900 9
memcached
STORED
get javatpoint
VALUE javatpoint 0 9
Memcached
END ?
add key flags exptime bytes [noreply]
value ?
add key 0 900 9
memcached
STORED
get key
VALUE key 0 9
Memcached
END ?
SET
: The SET
command is used to store data in the cache. It takes the following form:SET <key> <flags> <exptime> <bytes> [noreply]\r\n
<data>\r\n?
<key>
: The unique key under which the data will be stored.<flags>
: Optional flags that provide additional information about the data (e.g., data format).<exptime>
: Optional expiration time for the data, in seconds.<bytes>
: The number of bytes in the data block.[noreply]
: An optional parameter that instructs the server not to send a response to the client.GET
: The GET
command is used to retrieve data from the cache. It takes the following form:GET <key>\r\n
<key>: The key of the data to retrieve.?
DELETE
: The DELETE
command is used to remove data from the cache. It takes the following form:DELETE <key> [noreply]\r\n?
<key>
: The key of the data to delete.[noreply]
: An optional parameter that instructs the server not to send a response to the client.
INCREMENT/DECREMENT
: The INCR
and DECR
commands are used to increment or decrement numeric values stored in the cache. They take the following form:INCR <key> <value> [noreply]\r\n
DECR <key> <value> [noreply]\r\n?
<key>
: The key of the numeric value to modify.<value>
: The amount by which to increment or decrement the value.[noreply]
: An optional parameter that instructs the server not to send a response to the client.STATS
: The STATS
command is used to retrieve statistics about the Memcached server. It takes the following form:STATS\r\n?
FLUSH_ALL
: The FLUSH_ALL
command is used to clear all data from the cache. It takes the following form:FLUSH_ALL [delay]\r\n?
[delay]
: An optional delay (in seconds) before flushing the cache. replace key flags exptime bytes [noreply]
value ?
add key 0 900 9
memcached
STORED
get key
VALUE key 0 9
memcached
END
replace key 0 900 5
redis
get key
VALUE key 0 5
redis
END ?
append key flags exptime bytes [noreply]
value ?
NOT_STORED
is returned by Memcached. After this, we set one key and append data into it.append javatpoint 0 900 5
redis
NOT_STORED
set javatpoint 0 900 9
memcached
STORED
get javatpoint
VALUE javatpoint 0 14
memcached
END
append javatpoint 0 900 5
redis
STORED
get javatpoint
VALUE javatpoint 0 14
memcachedredis
END ?
prepend key flags exptime bytes [noreply]
value ?
NOT_STORED
is returned by Memcached. After this, we set one key and prepend data into it.prepend tutorials 0 900 5
redis
NOT_STORED
set tutorials 0 900 9
memcached
STORED
get tutorials
VALUE tutorials 0 14
memcached
END
prepend tutorials 0 900 5
redis
STORED
get tutorials
VALUE tutorials 0 14
redismemcached
END ?
delete key [noreply] ?
set javatpoint 0 900 9
memcached
STORED
get javatpoint
VALUE javatpoint 0 9
memcached
END
delete javatpoint
DELETED
get javatpoint
END
delete javatpoint
NOT_FOUND ?
stats ?
stats
STAT pid 1162
STAT uptime 5022
STAT time 1415208270
STAT version 1.4.14
STAT libevent 2.0.19-stable
STAT pointer_size 64
STAT rusage_user 0.096006
STAT rusage_system 0.152009
STAT curr_connections 5
STAT total_connections 6
STAT connection_structures 6
STAT reserved_fds 20
STAT cmd_get 6
STAT cmd_set 4
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 4
STAT get_misses 2
STAT delete_misses 1
STAT delete_hits 1
STAT incr_misses 2
STAT incr_hits 1
STAT decr_misses 0
STAT decr_hits 1
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 262
STAT bytes_written 313
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT expired_unfetched 1
STAT evicted_unfetched 0
STAT bytes 142
STAT curr_items 2
STAT total_items 6
STAT evictions 0
STAT reclaimed 1
END?
telnet localhost 11211
version?
python-memcached
library:import memcache
# Connect to Memcached server
client = memcache.Client(['localhost:11211'])
# Get version information
version_info = client.get_stats('version')
print(version_info)?
get_stats('version')
method.python-memcached
library, you typically don't need to explicitly close connections. However, you can release resources associated with the client by setting it to None
:import memcache
# Connect to Memcached server
client = memcache.Client(['localhost:11211'])
# Use the client...
# Close the connection (release resources)
client = None?
spymemcached
library, you can close the Memcached client instance when you're done using it:import net.spy.memcached.MemcachedClient;
import java.net.InetSocketAddress;
public class Main {
public static void main(String[] args) {
// Connect to Memcached server
MemcachedClient client = new MemcachedClient(new InetSocketAddress("localhost", 11211));
// Use the client...
// Close the connection (release resources)
client.shutdown();
}
}?
Memcached
extension, you can close the connection by calling the close()
method on the Memcached instance:// Connect to Memcached server
$memcached = new Memcached();
$memcached->addServer('localhost', 11211);
// Use the Memcached instance...
// Close the connection (release resources)
$memcached->quit();?