Simple operation of redis

A collection of redis operations

Collection Add Delete Query All

Set   sadd   srem   smembers(key)

List  lpush  lrem   lrange(key, 0, -1)

 

redis installation steps

1.tar xzf redis-2.8.24.tar.gz

2.cd redis-2.8.24

3.make 

 

1. Start

./redis-server redis.conf

2. Link to redis

./redis-cli -h ip address -p port

3. redis operation

add set key value

get get key

delete del key

Set valid time: expire key time (in seconds)

How to check how much time ttl key a certain key-value has

How to view all key keys * in current redis

4. Operation on List

Save data: lpush key value (add from the left)    

       rpush key value (added from the right)

Get data: lrange key 0 -1 get all

       lpop ticketline remove one from the left

       rpop ticketline removes one from the right

Specifies the number of elements to return

       LINDEX 

 

5. Operation on set

  sadd team "xiaoming"

  sadd team "xiaohong"

  sadd team "xiaobai"

  smembers team

  srem team "xiaoming"

  move team1 team2 move collection

 

6. Transactions

  MULTI start a thing

  EXEC executes a thing

7. redis subscription and publishing

 publish sends the information message to the specified channel 

 

channel 

 subscribe to subscribe to a given channel or channels for information

Guess you like

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