1. Discussion beyond data structures

1.1 Expiration Time

Delete the key after it expires in 30 seconds

expire pages:about 30
Copy the code

Deletes a key at a specific time

expireat pages:about 1356933600
Copy the code

It will delete the key at 12:00 am on December 31, 2012

TTL command The TTL command can be used to find out how long a piece of data can live

ttl pages:about
Copy the code

Persist terminates the expiration, making the expired TTL invalid and persistent

persist pages:about

Setex Setex allows you to set a string in a single atomic command and specify its lifetime

setex pages:about 30 '<h1>about us</h1>.... 'Copy the code

1.2 Publication and Subscriptions

To subscribe to

subscribe warnings
Copy the code

release

publish warnings "it's over 9000!"
Copy the code

You can subscribe to multiple channels

subscribe channel1 channel2 ...
Copy the code

Stop listening to a subscription with unsubscribe

A group of channel

Subscribe to a set of channels for a mode

Psubscribe Warnings :* punsubscribe stops a set of channels in a certain mode.Copy the code

Finally, notice the return value of the publish command, 1. This is the number of clients that received the message

1.3 Monitor and slowlog

The monitor command lets you monitor the status of Redis. It’s a great debugging tool that gives you insight into how your application interacts with Redis.

Do not use monitor commands in production; they are a debugging and development tool

Slowlog is also a great performance analysis tool

// Log all commands: config set slowlog-log-slower than 0Copy the code

Retrieve all logs, or the latest logs, by:

slowlog get
slowlog get 10
Copy the code

1.4 Sort (Sort)

It allows you to sort values in lists, sets, and ordered sets (ordered sets are sorted by weight, not the members of the set). In the simplest case, it allows us to do this:

rpush users:leto:guesses 5 9 10 2 4 10 19 2
sort users:leto:guesses
Copy the code

Returns the lowest to highest order of values.

sadd friends:ghanima leto paul chani jessica alia duncan
sort friends:ghanima limit 0 3 desc alpha
Copy the code

The command above demonstrates how to page sorted records (via limit), return results in descending order (via DESC), and sort them lexicographically rather than numerically (via alpha).

1.5 Scan (Scan)

Scan uses cursor to express cursors and realize paging.

The first call to scan specifies 0 as the cursor. Let’s look at an example of an initial call to SCAN, which specifies a matching pattern (optional) and a count (optional):

  scan 0 match bugs:* count 20
Copy the code

END