跳至主要内容

PHP连接memcached

 

##########################telnet连接
telnet 192.168.3.3 11211
stats
add abc 0 60 5
hello
add 是指令名  
abc是key的名字 (是以key/value存放), 
0 标志, 
60 表示数据存放 60s   
5表示 放入多大数据  
如果一个key已经存在,再放入是失败的
get abc
#######################php测试脚本
<?php
//连接
$mem = new Memcached;
$mem->addServer("192.168.16.31", 11211) or die ("Could not connect");
//$mem = memcache_connect('192.168.16.31', 11211);
//保存数据
$mem->set('key1', 'This is first value', 0, 60);
$val = $mem->get('key1');
echo "Get key1 value: " . $val ."</br>";

//替换数据
$mem->replace('key1', 'This is replace value', 0, 60);
$val = $mem->get('key1');
echo "Get key1 value: " . $val . "<br>";

//保存数组
$arr = array('aaa', 'bbb', 'ccc', 'ddd');
$mem->set('key2', $arr, 0, 60);
$val2 = $mem->get('key2');
echo "Get key2 value: ";
print_r($val2);
echo "<br />";

//删除数据
$mem->delete('key1');
$val = $mem->get('key1');
echo "delete key1<br>";
echo "Get key1 value: " . $val . "<br />";

//清除所有数据
$mem->flush();
echo "delete all<br>";
$val2 = $mem->get('key2');
echo "Get key2 value: ";
print_r($val2);
echo "<br />";

//关闭连接
$mem->quit();
?>
-------------------------------
返回结果
#################对比memcache
<?php
//连接
$mem = new Memcache;
$mem->connect("127.0.01",  11211);

//保存数据
$mem->set('key1', 'This is first value', 0, 60);
$val = $mem->get('key1');
echo "Get key1 value: " . $val ."<br />";

//替换数据
$mem->replace('key1', 'This is replace value', 0, 60);
$val = $mem->get('key1');
echo "Get key1 value: " . $val . "<br />";

//保存数组
$arr = array('aaa', 'bbb', 'ccc', 'ddd');
$mem->set('key2', $arr, 0, 60);
$val2 = $mem->get('key2');
echo "Get key2 value: ";
print_r($val2);
echo "<br />";

//删除数据
$mem->delete('key1');
$val = $mem->get('key1');
echo "Get key1 value: " . $val . "<br />";

//清除所有数据
$mem->flush();
$val2 = $mem->get('key2');
echo "Get key2 value: ";
print_r($val2);
echo "<br />";

//关闭连接
$mem->close();
?>
#################################################################
PS:memcached 连接服务器改成:
public bool addServer ( string $host , int $port [, int $weight = 0 ] )
public bool addServers ( array $servers )
关闭连接改成:
public bool Memcached::quit ( void )
参考网址:http://php.net/manual/zh/book.memcached.php




评论

  1. In 2012, there was a push for south Jersey to allow gamblers to use mobile units to gamble in casinos, pushed by Senator Jim Whelan, to compete with Las Vegas. At the time, mobile gaming units have been already adopted in Las Vegas in casinos, allowing casinos to extend gaming flooring to their outer premises. In 2012, the New Jersey Legislature permitted "the use of of} hand-held playing units at Atlantic City casinos," and was waiting on the Governor's signature to cross. The new regulation requires any on 바카라사이트 line casino that gives mobile sports wagering, and each mobile sports wagering platform supplier, to submit an in depth annual again to} the Commission. The finest on-line playing websites enable gamers to wager on sports and on line casino video games such as blackjack and slots.

    回复删除

发表评论

此博客中的热门博文

Django使用markdown

Django使用markdown 安装markdown Pygments xxxxxxxxxx pip install Pygments markdown 生成css文件 xxxxxxxxxx pygmentize -S default -f html -a .codehilite > pygments.css -S 选择高亮模板,查看支持的高亮模板 xxxxxxxxxx from pygments . styles import STYLE_MAP STYLE_MAP . keys () 在对应APP添加 templatetags文件夹 custom_markdown.py xxxxxxxxxx import markdown from django import template from django . template . defaultfilters import stringfilter from django . utils . safestring import mark_safe register = template . Library () #自定义filter时必须加上 @register . filter ( is_safe = True ) #注册template filter @stringfilter       #希望字符串作为参数 def custom_markdown ( value ):     return mark_safe ( markdown . markdown ( value ,         extensions =[ 'markdown.extensions.fenced_code' , 'markdown.extensions.codehilite' ],         safe_mode = True ,         enable_attributes = False )) 模板中引用 xxxxxxxxxx {% load custom_markdown %...

web管理openvpn

  web管理openvpn 一部署目标 客户端使用openvpn客户端使用证书密钥+用户密码验证登录,拨入内网 服务器端使用mysql存储用户信息,并加密用户密码 开发openvpn管理平台,可以web界面管理openvpn 指定人员IP,通过策略限制人员访问资源 二部署openvpn 1安装openvpn服务端 1.1环境 系统 centos7.3 IP地址 100.100.100.100 Openvpn版本 2.4.3 安装方式 YUM 数据库 percona-server-5.7.18-15 验证工具 pam_mysql openvpn插件版本 2.0.9 1.2安装依赖 yum -y install epel-release yum install pam-devel pam yum install -y easy-rsa yum -y install mariadb-server mariadb-devel mariadb-libs yum install -y cyrus-sasl cyrus-sasl-plain cyrus-sasl-devel cyrus-sasl-lib cyrus-sasl-gssapi 1.3安装openvpn 使用yum命令安装openvpn yum install -y openvpn 1.4配置证书密钥 复制证书密钥工具 #cp -R /usr/share/easy-rsa /etc/openvpn/ 进入工具目录 #cd /etc/openvpn/easy-rsa 修改证书生成信息 #vim /etc/openvpn/easy-rsa/2.0/vars export KEY_COUNTRY="CN" export KEY_PROVINCE="CA" export KEY_CITY="HangZhou" export KEY_ORG="xxx" export KEY_EMAIL="server_monitor@xxx.com" export KEY_OU="YunWei 重新加载 #source ./vars 重新产生CA证书 ./clean-all ./build-ca 创建服务端证书 ./build-key...

Django部署

Django部署   uwsgi配置 官方文档 : uwsgi-docs 选项 描述 chdir the base directory (full path) module Django's wsgi file master 启动管理主进程 processes 启动的进程数 threads 每个进程的线程数 uid 启动uwsgi的用户 gid 启动uwsgi的用户组 pidfile 进程号文件 max-requests 最大请求数 vacuum clear environment on exit 服务停止自动清理sock文件和pid文件 daemonize 日志目录 home python虚拟环境路径 socket scoket地址(tcp或者sock文件路径) chmod-socket sock文件权限 http uwsgi监听IP和端口 x [uwsgi] chdir = /opt/Platform module = Platform.wsgi master = True pidfile = /tmp/tzop.pid vacuum = True max-requests = 5000 processes = 8 #socket=/var/run/op_uwsgi.sock # unxi scoket need set chmod-socket #chmod-socket=666 #socket=127.0.0.1:8000 http = 127 .0.0.1:8000 #static-map = /static=/application/Platform/static daemonize = /opt/Platform/logs/uwsgi.log 启动 x uwsgi --ini tzop.ini 停止 x uwsgi --stop /tmp/tzop.pid 重载 x uwsgi --reload /tmp/tzop.pid nginx配置 uwsgi_pass 不对 location 目录转发 x server {       listen         80 ;       server_name _...