PHP操作redis基本操作

简单字符串存储 string

Redis::set('name', 'Taylor');

$test = Redis::get('name'); 

echo  $test;

//输出 Taylor

复杂字符串存储 Hash

Redis::hset('user','user1',json_encode(['a'=>'1111','b'=>'22222222']));

$user1 = Redis::hget('user','user1');

echo "";print_r(json_decode($user1,true));

//输出 Array ( [a] => 1111 [b] => 22222222 )

队列list

//进队列

$strQueueName = 'Test_bihu_queue'; 

Redis::rpush($strQueueName, json_encode(['uid' => 1,'name' => 'Job']));

Redis::rpush($strQueueName, json_encode(['uid' => 2,'name' => 'Tom']));

Redis::rpush($strQueueName, json_encode(['uid' => 3,'name' => 'John']));

//查看队列

$strCount = Redis::lrange($strQueueName, 0, -1);

echo "当前队列数据为: "; print_r($strCount);

//出队列

Redis::lpop($strQueueName);

你可能感兴趣的:(PHP操作redis基本操作)