Redis常用命令

2016-12-15 17:31:00
村里来的扫地僧
原创
1630
如何启动Redis-Server
	[root@linux-02 bin]# ./redis-server /redis/redis.conf 

进入Redis-cli
	[root@linux-02 bin]# redis-cli 
	127.0.0.1:6379> 


如何获取帮助:
	127.0.0.1:6379[1]> help
	redis-cli 3.2.5
	To get help about Redis commands type:
		  "help @<group>" to get a list of commands in <group>
		  "help <command>" for help on <command>
		  "help <tab>" to get a list of possible help topics
		  "quit" to exit

	To set redis-cli perferences:
		  ":set hints" enable online hints
		  ":set nohints" disable online hints
	Set your preferences in ~/.redisclirc
	127.0.0.1:6379[1]> help set

	  SET key value [EX seconds] [PX milliseconds] [NX|XX]
	  summary: Set the string value of a key
	  since: 1.0.0
	  group: string

  
help例子:
	127.0.0.1:6379[1]> help set

	  SET key value [EX seconds] [PX milliseconds] [NX|XX]
	  summary: Set the string value of a key
	  since: 1.0.0
	  group: string

	127.0.0.1:6379[1]> help @string

	  APPEND key value
	  summary: Append a value to a key
	  since: 2.0.0

	  BITCOUNT key [start end]
	  summary: Count set bits in a string
	  since: 2.6.0

	  BITFIELD key [GET type offset] [SET type offset value] [INCRBY type offset increment] [OVERFLOW WRAP|SAT|FAIL]
	  summary: Perform arbitrary bitfield integer operations on strings
	  since: 3.2.0

	  BITOP operation destkey key [key ...]
	  summary: Perform bitwise operations between strings
	  since: 2.6.0

	  BITPOS key bit [start] [end]
	  summary: Find first bit set or clear in a string
	  since: 2.8.7

	  DECR key
	  summary: Decrement the integer value of a key by one
	  since: 1.0.0

	  DECRBY key decrement
	  summary: Decrement the integer value of a key by the given number
	  since: 1.0.0

	  GET key
	  summary: Get the value of a key
	  since: 1.0.0

	  GETBIT key offset
	  summary: Returns the bit value at offset in the string value stored at key
	  since: 2.2.0

	  GETRANGE key start end
	  summary: Get a substring of the string stored at a key
	  since: 2.4.0

	  GETSET key value
	  summary: Set the string value of a key and return its old value
	  since: 1.0.0

	  INCR key
	  summary: Increment the integer value of a key by one
	  since: 1.0.0

	  INCRBY key increment
	  summary: Increment the integer value of a key by the given amount
	  since: 1.0.0

	  INCRBYFLOAT key increment
	  summary: Increment the float value of a key by the given amount
	  since: 2.6.0

	  MGET key [key ...]
	  summary: Get the values of all the given keys
	  since: 1.0.0

	  MSET key value [key value ...]
	  summary: Set multiple keys to multiple values
	  since: 1.0.1

	  MSETNX key value [key value ...]
	  summary: Set multiple keys to multiple values, only if none of the keys exist
	  since: 1.0.1

	  PSETEX key milliseconds value
	  summary: Set the value and expiration in milliseconds of a key
	  since: 2.6.0

	  SET key value [EX seconds] [PX milliseconds] [NX|XX]
	  summary: Set the string value of a key
	  since: 1.0.0

	  SETBIT key offset value
	  summary: Sets or clears the bit at offset in the string value stored at key
	  since: 2.2.0

	  SETEX key seconds value
	  summary: Set the value and expiration of a key
	  since: 2.0.0

	  SETNX key value
	  summary: Set the value of a key, only if the key does not exist
	  since: 1.0.0

	  SETRANGE key offset value
	  summary: Overwrite part of a string at key starting at the specified offset
	  since: 2.2.0

	  STRLEN key
	  summary: Get the length of the value stored in a key
	  since: 2.2.0

  
   
常用命令:
	127.0.0.1:6379> KEYS *
	1) "k1"
	2) "k3"
	3) "k2"
	127.0.0.1:6379> 

创建user002:
	127.0.0.1:6379> set user002 user002
	OK

获取user002:
	127.0.0.1:6379> get user002
	"user002"


Redis有多少个数据库:  16个数据库
 174 
 175 # Set the number of databases. The default database is DB 0, you can select
 176 # a different one on a per-connection basis using SELECT <dbid> where
 177 # dbid is a number between 0 and 'databases'-1
 178 databases 16


如何在数据库之间的切换:
	127.0.0.1:6379> SELECT 1
	OK
	127.0.0.1:6379[1]> 

进入某个库,创建库:
	127.0.0.1:6379[1]> set user003 user003
	OK
发表评论
壹 加 贰 =
评论通过审核后显示。