Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Select Command

Redis Select Command

Redis Connection

The Redis Select command is used to switch to the specified database; the database index is specified by a numeric value, starting from 0.

Syntax

The basic syntax of the redis Select command is as follows:



redis 127.0.0.1:6379> SELECT index 

Available Version

= 1.0.0

Return Value

Always returns OK.

Example



redis 127.0.0.1:6379> SET db_number 0         # 默认使用 0 号数据库

OK



redis 127.0.0.1:6379> SELECT 1                # 使用 1 号数据库

OK



redis 127.0.0.1:6379[1]> GET db_number        # 已经切换到 1 号数据库,注意 Redis 现在的命令提示符多了个 [1]

(nil)



redis 127.0.0.1:6379[1]> SET db_number 1

OK



redis 127.0.0.1:6379[1]> GET db_number

"1"



redis 127.0.0.1:6379[1]> SELECT 3             # 再切换到 3 号数据库

OK



redis 127.0.0.1:6379[3]>                      # 提示符从 [1] 改变成了 [3]

Redis Connection