Getting Started with Redis

Source: Internet
Author: User

To talk about the use of Redis. Windows directly downloads the. zip extract to add the extracted folder directly to the path of the system variable.

1. PS f:\myredis> redis-server. \redis.windows.conf ... [4712:04.1943.2.  - [4712:04.1956379 

Start the local service as described above. Local IP127.0.0.1 port number defaults to 6379 (can be modified in redis.windows.conf)

When we use it, we need to start a client by starting with a different command line (Windows recommends PowerShell with a more user-friendly interface)

127.0. 0.1 6379


The above command is connected to the Redis service that we have just opened, and we can also connect to a remotely deployed Redis service

Redis-cli-h host-p port-a Password (requires password)

2.redis type. The Redis cache is closer to the use of containers in the programming language. So it has a lot of data structures on its own:
[1] String Redis's string is like a key-value pair and is the most basic type of redis. Cache binaries are also supported, example:

" Rockderia " Get name " Rockderia "

[2] Hash type. First, it is itself a set of key-value pairs. This collection requires an identity in which the data in the form of a key-value pair exists as follows:

127.0.0.1:6379> Hmset User:1username Rockderia sss (error) ERR wrong number of arguments forHmset127.0.0.1:6379> Hmset User:1Username Rockseria AgeTenOK127.0.0.1:6379> Hgetall User:11)"username"2)"Rockseria"3)" Age"4)"Ten"127.0.0.1:6379> Hget User:1username"Rockseria"

As you can see, this type is very similar to the table in the Lua script.

[3] The list type. Not much to say is a linear list, you can use the operation of the index.

127.0.0.1:6379>lpush rocklist One (integer)1127.0.0.1:6379>lpush rocklist (integer)2127.0.0.1:6379>lpush rocklist Three (integer)3127.0.0.1:6379> Lrange rocklist0 21)"three"2)" Both"3)" One"

The data appears to be in reverse storage in the linked list.

[4] Set Type a collection of unordered unique values. The string type. Because the same hash structure, so the query is still a direct lock value, the complexity is O (1).

127.0.0.1:6379>sadd rockset Rock (integer)1127.0.0.1:6379>sadd rockset Lily (integer)1127.0.0.1:6379>sadd rockset Lily (integer)0127.0.0.1:6379>smembers Rockset1)"Lily"2)"Rock"

[5]zset ordered collection. Almost the same as set, but each element is associated with a number of double types, which makes it easy to sort. Also, the number of associated double types allows duplicates.

127.0.0.1:6379> Zadd Rockzset0.5Rock (integer)1127.0.0.1:6379> Zadd Rockzset0.6Lily (integer)1127.0.0.1:6379> Zadd Rockzset0.5Blaze (integer)1127.0.0.1:6379> Zrangebyscore Rockzset0 11)"Blaze"2)"Rock"3)"Lily"

3.redis Keys and Common commands
The keys are used for all containers on top. When Redis performs some operations, it needs to process the keys (the keys in the 5 structural examples above are, [1]name [2]user:1 [3]rocklist] [4]rockset [5]rockzset]
[1] When we delete a set of data, we can delete the key directly

127.0. 0.1:6379>1

[2] We can detect whether a key exists or not

127.0. 0.1:6379>0127.0. 0.1:6379>1

[3] Set expiration time (this is one of the focuses of using Redis.) There are many different formats for setting time

127.0. 0.1:6379> EXPIRE User:11127.0. 0.1:6379> exists User:11

After 20 seconds

127.0. 0.1:6379> exists User:10

[4] View keys (regular expressions supported)
The key to view all the data that already exists is the keys *

127.0. 0.1:6379> Keys *1"rockset"2"  Rocklist"3"name"

[5]move transfer data to database move key db

[6] PERSIST key to remove expiration time

[7] Pttl (msec)/ttl (SEC) key returns the remaining expiration time

127.0.0.1:6379> Set newname"Rock"OK127.0.0.1:6379> Keys *1)"Rockset"2)"rocklist"3)"newname"4)"name"127.0.0.1:6379> EXPIRE newname -(integer)1127.0.0.1:6379>pttl newname (integer)113201127.0.0.1:6379>pttl newname (integer)105775127.0.0.1:6379>persist newname (integer)1127.0.0.1:6379>pttl newname (integer)-1127.0.0.1:6379>

[8]rename/renamenx (guaranteed key Uniqueness) Change the name of key

[9]type Key returns the type of key

127.0. 0.1:6379> type rocklistlist

4. Pending update

Getting Started with Redis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.