Redis-2 - Basic Concepts

PING 

String skewer: SET runoobkey redis    GET runoobkey   DEL runoobkey

哈希(hash):HMSET runoobkey name "redis tutorial" description "redis basic commands for caching" likes 20 visitors 23000         HGETALL runoobkey

List (List) or so:   LPUSH runoobkey redis  LPUSH runoobkey mongodb  LRANGE mylist 0 - 1

集合(Set):SADD runoobkey redis  SADD runoobkey mongodb SMEMBERS runoobkey

有序集合(Sorted Set):ZADD runoobkey 1 redis ZADD runoobkey 2 mongodb ZRANGE runoobkey 010 WITHSCORES

Redis HyperLogLog:PFADD runoobkey "redis"  PFADD runoobkey "mongodb" PFCOUNT runoobkey

Redis 发布订阅:SUBSCRIBE redisChat  PUBLISH redisChat "Redis is a great caching technique"  PUBLISH redisChat "Learn redis by runoob.com"

 Redis transaction:

Redis transactions can execute multiple commands at once with two important guarantees:

  • Bulk operations are put into the queue buffer before sending the EXEC command.
  • After receiving the EXEC command, the transaction is executed. Any command in the transaction fails to be executed, and the rest of the commands are still executed.
  • During transaction execution, command requests submitted by other clients will not be inserted into the transaction execution command sequence.

A transaction goes through the following three stages from initiation to execution:

  • Start business.
  • Command enqueue.
  • Execute the transaction.
redis 127.0.0.1:6379> MULTI
OK

redis 127.0.0.1:6379> SET book-name "Mastering C++ in 21 days"
QUEUED

redis 127.0.0.1:6379> GET book-name
QUEUED

redis 127.0.0.1:6379> SADD tag "C++" "Programming" "Mastering Series"
QUEUED

redis 127.0.0.1:6379> SMEMBERS tag
QUEUED

redis 127.0.0.1:6379> EXEC
1) OK
2) "Mastering C++ in 21 days"
3) (integer) 3
4) 1) "Mastering Series"
   2) "C++"
   3) "Programming"

  

Redis 脚本:EVAL "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"2 key1 key2 first second

Redis Select command: 

redis 127.0 . 0.1 : 6379 > SET db_number 0          # default to use database number 0
OK

redis 127.0 . 0.1 : 6379 > SELECT 1                 # Use database number 1
OK

redis 127.0 . 0.1 : 6379 [ 1 ]> GET db_number # Has switched to database No. 1 , note that Redis now has more command prompts [ 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              # Switch to database No. 3 again
OK

redis 127.0 . 0.1 : 6379 [ 3 ]> # Prompt changed from [ 1 ] to [ 3 ]

 

 

 

 

 

 

 

 

 

 

 










Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324856124&siteId=291194637