Live2D

MemoryCache

1.安装

下载安装

wget http://www.memcached.org/files/memcached-1.6.7.tar.gz  #下载

tar -zxvf latest                                            #解压

./configure --prefix=/usr/local/memcached                   #配置

make && make test 																					#编译

sudo make install 																					#安装

在执行 ./configure --prefix=/usr/local/memcached 命令时可能会报以下错误image

解决方法:

安装libevent-devel

yum install libevent-devel

后台运行

/usr/local/memcached/bin/memcached -d -m 64M -u memcached -l wl -p 11211 -c 256 -P /tmp/memcached.pid
或者
/usr/local/memcached/bin/memcached -u memcached  -p 11211 -m 64m -d

参数解释

  • -d是启动一个守护进程
  • -m是分配给Memcache使用的内存数量,单位是MB
  • -u是运行Memcache的用户
  • -l是监听的服务器IP地址,可以有多个地址
  • -p是设置Memcache监听的端口
  • -c是最大运行的并发连接数
  • -P是设置保存Memcache的pid文件

2.操作MemeoryCache

安装telnet

在操作MemeoryCache之前安装 telnet

yum list |grep telnet
yum -y install telnet-server.x86_64
yum -y install telnet.x86_64

yum list |grep xinetd
yum -y install xinetd.x86_64

启动服务

systemctl start telnet.socket
systemctl start xinetd
命令行连接
telnet localhost 11211
set命令

设置key和value,如果存在就更新

#设置值
set hello 1 0 5
world
#获取值
get hello
  • hello: 表示key
  • 1 :存储键值对额外的信息
  • 0 :过期时间,0代表永久
  • 5 :存储的字节数
  • world:存储的value
add命令

添加key和value,存在不更新

add addCommand 0 0 7
command
replace命令

替换已经存在的值

replace addCommand 0 20 7
command
append命令

在后面追加数据

append hello 1 0 6
kotlin
prepend命令

在前面追加数据

prepend hello 1 0 4
i am
cas命令

乐观锁的实现

#设置key-value
set haha 0 0 3
hei
#获取唯一令牌
gets haha
VALUE haha 0 3 14
#设置cas
cas haha 0 0 6 14
heihei
get命令

获取单个key的value

get hello

获取多个key的value,用空格隔开

get hello haha
delete命令

删除数据

delete hello
posted @ 2022-04-06 10:49  没有梦想的java菜鸟  阅读(178)  评论(0编辑  收藏  举报