技术饭

磁盘持久化redis的安装与使用注意事项

copylian    0 评论    9693 浏览    2017.01.04

磁盘持久化redis的安装与使用注意事项,在适用redis的过程中我们需要注意哪些事项呢,例如:php需要安装php_redis.dll扩展与php_igbinary.dll,php_igbinary.dll在前,php_redis.dll在后,以及一些常用的redis命令。仅供参考!

1、下载redius并且安装http://www.redis.net.cn/

2、php需要安装php_redis.dll扩展与php_igbinary.dll,php_igbinary.dll在前,php_redis.dll在后

3、基本命令

   1)、incr命令:自增长数值;incr count:user:108:index:pv

   2)、setbit + bitcount:统计活跃度;setbit count:user:1008 1 2,bitcount count:user:108

   3)、setex:设置缓存时间,设置session;setex name 100 admin

   4)、hset hash:设置关联数组;hset hash:user:108 password admin

   5)、hget hash:获取单个关联数组值,hget hash:user:108 password

   6)、hgetall hash:获取所有,hgetall hash:user:108

   7)、hmset:同时设置多个关联数组值,hmset hash:user:108 username admin passwd admin age 30

4、redis实例:

<?php
$options = [   
     'type' => 'redis', //类型
     'expire' => 7200, //缓存时间    
     'prefix' => 'aikehou' //缓存前缀
]
$redis = Cache::connect($options);
if($redis->get($types)){   
     //获取数据代码   
     $redis->set('types',$data);  
} else {   
     $data = $redis->get($types);
}
return $data;
?>

5、redis优化

    1)、使用json

      json_encode() :将数组或对象转成json格式

      json_decode() :将json格式转成数组或对象

    2)、序列化serialize()与反序列化unserialize()

      serialize() :将数组或对象转成文本格式

      un_serialize() :将j数据反序列化

只袄早~~~
感谢你的支持,我会继续努力!
扫码打赏,感谢您的支持!

文明上网理性发言!

  • 还没有评论,沙发等你来抢