FreeBSD 14
Sponsored Link

Memcached : Basic Usage2024/09/16

 

This is Basic Usage of Memcached when connecting with Telnet client.

[1] Install Telnet client.
root@dlp:~ #
pkg install -y freebsd-telnetd
[2] This is Basic Usage of Memcached.
# connect to local Memcached

root@dlp:~ #
telnet localhost 11211

Trying ::1...
Connected to localhost.
Escape character is '^]'.

# show status of Memcached
stats
STAT pid 1092
STAT uptime 80
STAT time 1726449169
STAT version 1.6.28
STAT libevent 2.1.12-stable
STAT pointer_size 64
STAT rusage_user 0.000000
STAT rusage_system 0.005038
STAT max_connections 1024
STAT curr_connections 2
STAT total_connections 3

.....
.....

STAT moves_to_cold 0
STAT moves_to_warm 0
STAT moves_within_lru 0
STAT direct_reclaims 0
STAT lru_bumps_dropped 0
END

# save data (on memory)
# set [Key] [Flag] [Validity Term(sec)] [Data Size(byte)]
# Flag : 0=compression off, 1=compression on
# Validity Term=0 means indefinite
# after inputting command above, input a Value of the Key
set test_key 0 0 10
test_value
STORED

# refer to Value of a Key
get test_key
VALUE test_key 0 10
test_value
END

# replace Value of a Key
replace test_key 0 0 11
test_value2
STORED
get test_key
VALUE test_key 0 11
test_value2
END

# append Value of a Key
append test_key 0 0 5
,test
STORED
get test_key
VALUE test_key 0 16
test_value2,test
END

# prepend Value of a Key
prepend test_key 0 0 6
test1,
STORED
get test_key
VALUE test_key 0 22
test1,test_value2,test
END

# delete a Key
delete test_key
DELETED

# increment Value of a Key
set mycounter 0 0 1
1
STORED
incr mycounter 1
2
get mycounter
VALUE mycounter 0 1
2
END

# decrement Value of a Key
decr mycounter 1
1
get mycounter
VALUE mycounter 0 1
1
END

# delete all caching data on memory
flush_all
OK

# exit
quit
[3] For CAS (Check And Set) operation, use [cas] command like follows.
# refer to Value with CAS ID
# on the example below, CAS ID = 9

gets test_key
VALUE test_key 0 10 9
test_value
END

# update data with cas command
# cas [Key] [Flag] [validity term(sec)] [data size(byte)] [CAS ID]
cas test_key 0 0 11 9
test2_value
STORED
gets test_key
VALUE test_key 0 11 10
test2_value
END
Matched Content