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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-18 09:16:17
Original
1163 people have browsed it

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>
Copy after login

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.

Related labels:
Statement of this Website
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
Latest Issues
php redis connection problem
From 1970-01-01 08:00:00
0
0
0
About a small error in the redis manual
From 1970-01-01 08:00:00
0
0
0
python2.7 - django cannot connect to redis
From 1970-01-01 08:00:00
0
0
0
I can't connect to redis using php
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template