Home >Backend Development >PHP Tutorial >node.js - How to specify the target database of sadd in php

node.js - How to specify the target database of sadd in php

WBOY
WBOYOriginal
2016-08-18 09:16:171138browse

For example, I want to insert data into library No. 1 instead of the default library No. 0
I know that in the command line, use select 1 and then sadd xxx yyy,
But how do I write the code in php?

Reply content:

For example, I want to insert data into library No. 1 instead of the default library No. 0
I know that in the command line, use select 1 and then sadd xxx yyy,
But how do I write the code in php?

<code><?php

$redis = new Redis();
$redis->connect('127.0.0.1');
$redis->select('1');

$redis->set('test',time());

echo $redis->get('test');

$redis->sAdd('s', 5);
$redis->sAdd('s', 4);
$redis->sAdd('s', 2);
$redis->sAdd('s', 1);
$redis->sAdd('s', 3);

var_dump($redis->sort('s')); // 1,2,3,4,5</code>

PhpRedis - a redis extension written in C, fast, slightly troublesome to install

predis - a redis extension written in PHP. It is not as fast as PhpRedis, but it is more convenient to use it directly with composer

Both the above two libraries can do what you want.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn