Using redis under windows, getting started with Redis, basic commands of Redis

Using redis under windows, getting started with Redis, basic commands of Redis

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..

Sweet Potato YaoSeptember 13, 2016 15:19:26 Tuesday

http://fanshuyao.iteye.com/

 

 

1. The use of Redis

REmote DIctionary Server (Redis) is a key-value storage system written by Salvatore Sanfilippo .

 

 

Advantages of Redis

Extremely high performance - Redis can read at 110,000 times /s and write at 81,000 times /s .

Rich Data Types Redis supports Strings, Lists, Hashes, Sets and Ordered Sets data type operations for binary cases .

Atomic – All Redis operations are atomic, and Redis also supports atomic execution of several operations after they are combined.

Rich features Redis also supports publish/subscribe, notifications , key expiration and more.

 

How is Redis different from other key-value stores?

Redis has more complex data structures and provides atomic operations on them, which is an evolutionary path different from other databases. Redis data types are based on basic data structures and are transparent to programmers without additional abstraction.

Redis runs in memory but can be persisted to disk, so when reading and writing different data sets at high speed, memory needs to be weighed, and the amount of data should not be larger than hardware memory. Another advantage in terms of in-memory databases is that it is very simple to operate in memory compared to the same complex data structures on disk, so Redis can do a lot of things with a lot of internal complexity. At the same time, they are compact in terms of on-disk format and are generated appending because they do not require random access.

 

1. The redis directory structure after installation is as follows:

 

Download address: https://github.com/MicrosoftArchive/redis/releases

 

 

Among them, you need to pay attention to the files marked in red.

 

2. If your redis is installed in:

D:\Redis-x64-3.2.100

 

3. In the windows command line, enter the D drive

C:\Users\lqyao>d:

 

4. Re-enter the directory ( D:\Redis-x64-3.2.100 ):

D:\>cd D:\Redis-x64-3.2.100



 

5. Start the redis service:

D:\Redis-x64-3.2.100>redis-server.exe redis.windows.conf




 

The port number is: 6379

Note: Do not close this window, otherwise you will not be able to access the server.

 

6. Enable the client:

Open a new windows command window, and then directly enter the command to start the client:

D:\Redis-x64-3.2.100\redis-cli.exe




 

 

Seeing this means the entry is successful:

127.0.0.1:6379>

 

Then you can set the value and get the value.

 

 

7. Set a value

When you type set on the keyboard , the command line will be automatically prompted (very good):

127.0.0.1:6379> set key value [EX seconds] [PX milliseconds] [NX|XX]

 

Of course, we may not need to set too much, just set it as a key-value pair, as follows:

127.0.0.1:6379> set age 20

OK

 

Return ok to indicate success.

 

8. Take the value according to the key

Similarly, when you hit get , there will be a prompt:

127.0.0.1:6379> get key

 

Get the value of the age property you just set:

127.0.0.1:6379> get age

"20"

 

correctly returned 20

 

9. Redis supports five data types :

string (string)

hash _

list (list)

set (collection)

zset (sorted set : sorted set )

 

10. Delete the properties of the settings

When you enter del on the keyboard , there will be a prompt:

127.0.0.1:6379> del key [key ...]

 

Delete the age just now :

127.0.0.1:6379> del age

(integer) 1

 

 

If the key is deleted successfully, the command will output (integer) 1 after the command is executed , otherwise it will output (integer) 0

 

11. Delete and then query age :

127.0.0.1:6379> get age

(nil)

 

 

12. Check if it exists

127.0.0.1:6379> exists age

(integer) 1

127.0.0.1:6379> exists tom

(integer) 0

 

Returns 1 if it exists, returns 0 if it does not exist

 

13. EXPIRE key seconds Set the expiration time for the given key :

Set age to expire in 20 seconds:

127.0.0.1:6379> expire age 20

(integer) 1

 

14. PEXPIRE key milliseconds sets the expiration time of the key in milliseconds :

Same as 13 , only the time is in milliseconds.

 

15. The PERSIST key removes the expiration time of the key, and the key will persist:

127.0.0.1:6379> persist age

(integer) 1

 

16. TTL key in seconds, returns the remaining time to live (TTL, time to live) for a given key :

127.0.0.1:6379> ttl age

(integer) -1

 

Returning -1 means that the key value will not expire.

 

17. PTTL key returns the remaining expiration time of the key in milliseconds :

Same as 16.

 

18. RANDOMKEY returns a random key from the current database :

127.0.0.1:6379> randomkey

"myname"

 

19. RENAME key newkey Modify the name of the key :

127.0.0.1:6379> rename outtime mytime

OK

 

20. RENAMENX key newkey Rename the key to newkey only when newkey does not exist :

127.0.0.1:6379> renamenx mytime age

(integer) 0

 

127.0.0.1:6379> renamenx mytime my

(integer) 1

 

When newkey exists, return 0 , indicating failure. When newkey does not exist, return 1 , indicating success.

 

21. TYPE key returns the type of the value stored by the key :

127.0.0.1:6379> type age

string

 

 

22. A small tip: when you enter a part of the only certain command, press the Tab key, it will be automatically completed, a bit like Linux .

 

For more information, please download the attachment to view.

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..

Sweet Potato YaoSeptember 13, 2016 15:19:26 Tuesday

http://fanshuyao.iteye.com/

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326646218&siteId=291194637
Recommended