redis的基本操作小记录

// 存储字符串(后者覆盖前者)

runoobkey zhi
set runoobkey zhi2
get runoobkey

// 存储多个哈希值

 HMSET 'user:1' zhi1 zhi2 zhi3 zhi4
 HGETALL 'user:1'

// 列表list

LPUSH 'queue:1' redis
LPUSH 'queue:1' mongodb
LPUSH 'queue:1' 
LRANGE 'queue:1' 0 -1

// set 集合

SADD 'dui:1' redis
SADD 'dui:1' mogondb
SADD 'dui:1' redis
SMEMBERS 'dui:1'

1) "mogondb"
2) "redis"

// 有序集合

 ZADD 'sort:1' 1 redis
 ZADD 'sort:1' 1 redis //插入失败,返回0
 ZADD 'sort:1' 1 mysql
 ZADD 'sort:1' 1 mogondb
1) "mysql"
2) "redis"
3) "mogondb"

---------------------以下是php的redis操作------------------------

<?php
echo "<pre>";

//print_r(phpinfo());die;

$redis = new Redis();

$redis->connect("127.0.0.1",6379);
//$redis->set('zhi1','我是哈666');
//$redis->delete("zhi1");
//echo $redis->get("zhi1");

//$redis->delete("test");
//$redis->RPush('test','ni');
//$redis->RPush('test','hao');

//$redis->lRemove('test1','a','2');

$redis->delete("test1");
$redis->lPush('test1','a');
$redis->lPush('test1','b');
$redis->RPush('test1','a');


echo "<pre>";
print_r($redis->lgetrange('test1',0,-1));die;
?>
posted @ 2018-02-02 17:04  蜗牛使劲冲  阅读(2)  评论(0编辑  收藏  举报  来源