redis学习笔记

2019-1-24 张宇童

redis

$redis = new Redis;
$redis->connect('localhost',6379); 

字符串类型操作

添加

$redis->set('key','value');//设置一个字符串类型的键值 $redis->mset(['key1'=>'value1','key2'=>'value2','key3'=>'value3']);//批量添加数据 $redis->setex('key',10,'value');//添加一个生命周期10秒的数据 $redis->setnx('key','value');//添加前检查键值是否存在,添加或不添加 

修改

$redis->set('key','value');
$redis->incr('key');//让key的值自增1 $redis->incrBy('key',3);//让key的值自增三 $redis->decr('key');//让key的值自减1 $redis->decrBy('key',3);//让key的值自减3 

获取

$redis->get('key');//获取一个键值 $redis->mget(['key','key1','key2']);//批量获取键值 

获取

$redis->delete('key');//删除key的键值 $redis->delete(['key','key1']);//批量删除键值 
%23%20redis%0A%60%60%60php%0A%24redis%20%3D%20new%20Redis%3B%0A%24redis-%3Econnect('localhost'%2C6379)%3B%0A%60%60%60%0A%23%23%20%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%B1%BB%E5%9E%8B%E6%93%8D%E4%BD%9C%0A%23%23%23%23%20%E6%B7%BB%E5%8A%A0%0A%60%60%60php%0A%24redis-%3Eset('key'%2C'value')%3B%2F%2F%E8%AE%BE%E7%BD%AE%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%B1%BB%E5%9E%8B%E7%9A%84%E9%94%AE%E5%80%BC%0A%24redis-%3Emset(%5B'key1'%3D%3E'value1'%2C'key2'%3D%3E'value2'%2C'key3'%3D%3E'value3'%5D)%3B%2F%2F%E6%89%B9%E9%87%8F%E6%B7%BB%E5%8A%A0%E6%95%B0%E6%8D%AE%0A%24redis-%3Esetex('key'%2C10%2C'value')%3B%2F%2F%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F10%E7%A7%92%E7%9A%84%E6%95%B0%E6%8D%AE%0A%24redis-%3Esetnx('key'%2C'value')%3B%2F%2F%E6%B7%BB%E5%8A%A0%E5%89%8D%E6%A3%80%E6%9F%A5%E9%94%AE%E5%80%BC%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%EF%BC%8C%E6%B7%BB%E5%8A%A0%E6%88%96%E4%B8%8D%E6%B7%BB%E5%8A%A0%0A%60%60%60%0A%23%23%23%23%20%E4%BF%AE%E6%94%B9%0A%60%60%60php%0A%24redis-%3Eset('key'%2C'value')%3B%0A%24redis-%3Eincr('key')%3B%2F%2F%E8%AE%A9key%E7%9A%84%E5%80%BC%E8%87%AA%E5%A2%9E1%0A%24redis-%3EincrBy('key'%2C3)%3B%2F%2F%E8%AE%A9key%E7%9A%84%E5%80%BC%E8%87%AA%E5%A2%9E%E4%B8%89%0A%24redis-%3Edecr('key')%3B%2F%2F%E8%AE%A9key%E7%9A%84%E5%80%BC%E8%87%AA%E5%87%8F1%0A%24redis-%3EdecrBy('key'%2C3)%3B%2F%2F%E8%AE%A9key%E7%9A%84%E5%80%BC%E8%87%AA%E5%87%8F3%0A%60%60%60%0A%23%23%23%23%20%E8%8E%B7%E5%8F%96%0A%60%60%60php%0A%24redis-%3Eget('key')%3B%2F%2F%E8%8E%B7%E5%8F%96%E4%B8%80%E4%B8%AA%E9%94%AE%E5%80%BC%0A%24redis-%3Emget(%5B'key'%2C'key1'%2C'key2'%5D)%3B%2F%2F%E6%89%B9%E9%87%8F%E8%8E%B7%E5%8F%96%E9%94%AE%E5%80%BC%0A%60%60%60%0A%23%23%23%23%20%E8%8E%B7%E5%8F%96%0A%60%60%60php%0A%24redis-%3Edelete('key')%3B%2F%2F%E5%88%A0%E9%99%A4key%E7%9A%84%E9%94%AE%E5%80%BC%0A%24redis-%3Edelete(%5B'key'%2C'key1'%5D)%3B%2F%2F%E6%89%B9%E9%87%8F%E5%88%A0%E9%99%A4%E9%94%AE%E5%80%BC%0A%60%60%60%0A%23%23%20%E9%9B%86%E5%90%88%0A%23%23%23%20%E6%97%A0%E5%BA%8F%E9%9B%86%E5%90%88%0A%23%23%23%23%20%E6%B7%BB%E5%8A%A0%0A%60%60%60php%0A%24redis-%3Esadd('key'%2C'value')%3B%2F%2F%E5%9C%A8key%E7%9A%84%E9%9B%86%E5%90%88%E4%B8%AD%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E5%80%BC%0A%24redis-%3Esadd('key'%2C'value1'%2C'value2')%3B%2F%2F%E5%9C%A8key%E7%9A%84%E9%9B%86%E5%90%88%E4%B8%AD%E6%B7%BB%E5%8A%A0%E5%A4%9A%E4%B8%AA%E9%94%AE%E5%80%BC%0A%60%60%60%0A%23%23%23%23%20%E4%BF%AE%E6%94%B9%0A%60%60%60php%0A%24redis-%3Esmove('key1'%2C'key2'%2C'value')%3B%2F%2F%E5%B0%86key1%E7%9A%84value%E7%A7%BB%E5%8A%A8%E5%88%B0key2%E4%B8%AD%0A%60%60%60%0A%23%23%23%23%20%E8%8E%B7%E5%8F%96%0A%60%60%60php%0A%24redis-%3Esmembers('key')%3B%2F%2F%E8%8E%B7%E5%8F%96%E9%94%AE%E4%B8%AD%E6%89%80%E6%9C%89%E5%80%BC%0A%24redis-%3Essize('key')%3B%2F%2F%E8%8E%B7%E5%8F%96%E9%94%AE%E4%B8%AD%E7%9A%84value%E6%95%B0%E9%87%8F%0A%24redis-%3Esrandmember('key')%3B%2F%2F%E9%9A%8F%E6%9C%BA%E8%8E%B7%E5%8F%96%E4%B8%80%E4%B8%AA%E5%80%BC%0A%24redis-%3Esinter('key1'%2C'key2')%3B%2F%2F%E8%8E%B7%E5%8F%96%E4%B8%A4%E4%B8%AA%E9%9B%86%E5%90%88%E7%9A%84%E4%BA%A4%E9%9B%86%0A%24redis-%3Esunion('key1'%2C'key2')%3B%2F%2F%E8%8E%B7%E5%8F%96%E4%B8%A4%E4%B8%AA%E9%9B%86%E5%90%88%E7%9A%84%E5%B9%B6%E9%9B%86%0A%24redis-%3Esdiff('key1'%2C'key2')%3B%2F%2F%E8%8E%B7%E5%8F%96%E4%B8%A4%E4%B8%AA%E9%9B%86%E5%90%88%E7%9A%84%E5%B7%AE%E9%9B%86%0A%24redis-%3Esismember('key'%2C'value')%3B%2F%2F%E6%A3%80%E6%B5%8B%E5%80%BC%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%0A%60%60%60%0A%23%23%23%23%20%E5%88%A0%E9%99%A4%0A%60%60%60php%0A%24redis-%3Esrem('key'%2C'value')%3B%2F%2F%E8%BE%93%E5%87%BA%E9%9B%86%E5%90%88%E4%B8%AD%E7%9A%84%E4%B8%80%E4%B8%AA%E5%80%BC%0A%60%60%60%0A%23%23%23%20%E6%9C%89%E5%BA%8F%E9%9B%86%E5%90%88%0A%23%23%23%23%20%E6%B7%BB%E5%8A%A0%0A%60%60%60php%0A%24redis-%3Ezadd('key'%2C10%2C'value')%3B%2F%2F%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E5%80%BC%EF%BC%8C%E6%9D%83%E9%87%8D%E4%B8%BA10%0A%60%60%60%0A%23%23%23%23%20%E8%8E%B7%E5%8F%96%0A%60%60%60php%0A%24redis-%3Ezrange('key'%2C0%2C-1)%3B%2F%2F%E8%8E%B7%E5%8F%96%E9%9B%86%E5%90%88%E4%B8%AD%E6%89%80%E6%9C%89%E5%80%BC%0A%24redis-%3Ezrevrange('key'%2C0%2C-1)%3B%2F%2F%E8%8E%B7%E5%8F%96%E9%9B%86%E5%90%88%E4%B8%AD%E6%89%80%E6%9C%89%E5%80%BC%EF%BC%8C%E5%80%92%E5%BA%8F%0A%24redis-%3Ezrangebyscore('key'%2C0%2C1)%3B%2F%2F%E6%8C%89%E6%9D%83%E9%87%8D%E8%8C%83%E5%9B%B4%E8%8E%B7%E5%8F%96%E5%80%BC%0A%24redis-%3Ezrevrangebyscore('key'%2C0%2C1)%3B%2F%2F%E6%8C%89%E6%9D%83%E9%87%8D%E8%8C%83%E5%9B%B4%E8%8E%B7%E5%8F%96%E5%80%BC%EF%BC%8C%E5%80%92%E5%BA%8F%0A%24redis-%3Ezcount('key'%2C0%2C10)%3B%2F%2F%E8%BF%94%E5%9B%9E%E6%9D%83%E9%87%8D%E5%8C%BA%E9%97%B4%E7%9A%84%E5%85%83%E7%B4%A0%E4%B8%AA%E6%95%B0%0A%24redis-%3Ezsize('key')%3B%2F%2F%E8%BF%94%E5%9B%9E%E9%9B%86%E5%90%88%E4%B8%AD%E7%9A%84%E5%85%83%E7%B4%A0%E4%B8%AA%E6%95%B0%0A%24redis-%3Ezcore('key'%2C'value')%3B%2F%2F%E8%8E%B7%E5%8F%96%E5%8D%95%E4%B8%AA%E5%80%BC%E5%BE%97%E6%9D%83%E9%87%8D%0A%24redis-%3Ezrank('key'%2C'value')%3B%2F%2F%E8%8E%B7%E5%8F%96%E5%80%BC%E7%9A%84%E6%8E%92%E5%90%8D%0A%24redis-%3Ezrevrank('key'%2C'value')%3B%2F%2F%E8%8E%B7%E5%8F%96%E5%8D%95%E4%B8%AA%E5%80%BC%E7%9A%84%E5%80%92%E5%BA%8F%E6%8E%92%E5%90%8D%0A%60%60%60%0A%23%23%23%23%20%E5%88%A0%E9%99%A4%0A%60%60%60php%0A%24redis-%3Ezrem('key'%2C'value')%3B%2F%2F%E5%88%A0%E9%99%A4%E5%80%BC%0A%60%60%60%0A%23%23%23%23%20%E4%BF%AE%E6%94%B9%0A%60%60%60php%0A%24redis-%3Ezincrby('key'%2C3%2C'value')%3B%2F%2F%E8%AE%A9value%E7%9A%84%E6%9D%83%E9%87%8D%E5%9C%A8%E5%8E%9F%E5%9F%BA%E7%A1%80%E4%B8%8A%E5%8A%A03%0A%60%60%60

评论:

123
2019-03-22 11:22
hhh垃圾
西安SEO优化
2019-01-26 13:00
有些没看懂啊

发表评论:

Powered by emlog