Redis introduction and Common commands, redis introduction Common commands

Source: Internet
Author: User
Tags download redis redis download redis windows redis cluster redis labs redis server

Redis introduction and Common commands, redis introduction Common commands
Redis introduction and Common commands

Redis is an open-source, BSD-based, advanced key-value cache and storage (store) system. Redis keys include string, hash, list, set, sorted set, bitmap, and hyperloglog, which are often called Data Structure servers. You can run atomic operations on these types, such as appending strings, adding values in the hash, adding an element to the List, and calculating the intersection, union, and difference sets of the set, or get the highest ranking element from the sorted set.

To achieve high performance, Redis uses a memory (in-memory) dataset (dataset ). Based on your application scenario, you can dump the dataset to the disk at intervals, or append each command to the log for persistence. Persistence can also be disabled. If you only need a network-based memory cache with rich functions.

Redis also supports master-slave asynchronous replication, which automatically reconnects to the local reconnection during non-blocking initial synchronization and network disconnection. Other features include:

  • Transactions
  • Subscription/release
  • Lua script
  • Key with TTL
  • LRU recovery Jian
  • Automatic failover (failover)

You can use Redis in multiple languages.

Redis is written in ansi c and runs on Most POSIX systems, such as Linux, * BSD, and OS X, without additional dependencies. Redis is developed and fully tested under Linux and OS X. We recommend that you use Linux as the deployment environment. Redis can also run on a Solaris-derived system, such as SmartOS, but the support needs to be enhanced. There is no officially supported Windows build version, but Microsoft has developed and maintained a 64-bit Windows version.

For more information:

Wikipedia:

Redis is an in-memory database open-source software project sponsored by Redis Labs. It is networked, in-memory, and stores keys with optional durability.

Redis. io

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

Configure linux in redis

Linux download Installation Reference official website https://redis.io/download

Windows Configuration

The official redis website does not provide support for Windows, but Microsoft's open-source team has developed a Windows version. The project address is https://github.com/msopentech/redis. I 'd like to see it all the time. It's a great deal of flexibility !!!

Download redis Windows version from here https://github.com/MSOpenTech/redis/releases, here I want to feel again, I used the last configuration 2.4.5 version, the configuration of that version also needs to manually execute the command to install the service, manually configure environment variables. Now everything is automated. After the installation, you can add the installation directory to the environment variables when the service is automatically installed and installed.

Download the latest release installation package, decompress it, and install it. We recommend that you add it to the environment variable.

Redis Common commands connect to a remote redis Server
1 redis-cli -h hostname/ip [-p port] [-a password]2 3 redis-cli - 172.16.20.233 -p 6379

 

Parameter description

  • -H domain name or IP address
  • -P port number (the default port number is 6379)
  • -A access password (by default, password access is not required. To set a password, you can change the password of redis. conf.requirepassNode)
Basic operations

Note: The command name is case-insensitive, and the key and value are case-sensitive.

1 # select a database, database 2 SELECT index 3 4 whose index is 0 by default # obtain the key 5 in the cache # view all KEYS in the cache 6 KEYS * 7 8 # Fuzzy match query the key 9 KEYS aa * in the cache * 10 KEYS * aaa11 KEYS aa * bb12 13 # determine whether the key EXISTS 14 EXISTS key [key...] 15 16 # return value description 17 #-1: 18 #-0: 19 20 # obtain value21 GET key22 23 based on the key # return value description 24 #-(nil ): key does not exist 25 26 # obtain value based on key substring27 GETRANGE key start end28 29 # update key value returns the old value30 GETSET key value31 32 # obtain the value of multiple keys simultaneously 33 MGET key [key...] 34 35 # SET/update cache value 36 SET key value [EX seconds] [PX milliseconds] [NX | XX] 37 38 # parameter description 39 #-EX: SET expiration time, the Unit is 40 seconds #-PX: Set the expiration time, in milliseconds 41 #-NX: The value42 of the key is set only when the key does not exist #-XX: only when the key exists can the value43 44 SET key value PX milliseconds45 SET key value EX seconds NX 46 SET key value XX47 48 # It is SET only when the key does not exist, same effect as 'set key value NX '49 SETNX key value50 51 # rewrite part of the value corresponding to the key 52 SETRANGE key offset value53 54 # Get the length of the value corresponding to the key 55 STRLEN key56 57 # according key: Delete the value in the cache 58 DEL key [key...] 59 60 # reduce the integer value by 61 DECR key62 63 # reduce the integer value by decrement64 DECRBY key decrement 65 66 # Add a 67 INCR key68 69 # integer value reduce increment70 INCRBY key increment

 

More key operations
1 # Set the key expiration time in seconds 2 EXPIRE key seconds 3 4 # Set the UNIX timestamp of the key expiration time in seconds 5 EXPIREAT key timestamp 6 7 # in milliseconds set key expiration time 8 PEXPIRE key milliseconds 9 10 # UNIX timestamp 11 PEXPIREAT key milliseconds-timestamp12 13 # MOVE key to another database14 MOVE key db15 16 # the expiration time of the key to be removed, set to not expire 17 PERSIST key18 19 # Unit of the remaining survival time for obtaining the key is seconds, and the unit of expiration time is seconds 20 TTL key21 22 # return value description 23 #-2: key does not exist 24 #-1: key exists, but the expiration time is not set to 25 26 # The unit for obtaining the remaining survival time of the key is milliseconds, how long will the expiration time be measured in milliseconds 27 PTTL key28 29 # Get A randomly generated key30 RANDOMKEY31 32 # RENAME a key33 RENAME key newkey34 35 # Get the Data TYPE of the key stored value 36 TYPE key37 38 # list or set SORT 39 SORT key

 

More commands

More references https://redis.io/commands

Remote Redis debugging
# Anonymous access to redis-cli-h 172.16.0000233-p 6479 # password access to redis-cli-h 172.16.0000233-p 6479-a p @ ssword

 

  1. Use the keys fuzzy query to query the complete name of the key
# Keykeys * aaa ending with aaa # keykeys aaa starting with aaa * # fully fuzzy match keykeys containing aaa *

 

  1. Find the desired key and copy the complete key name. If the return value is(empty list or set), It indicates that such a key does not exist. Check whether your mode is correct. If it is correct, it indicates that there is no key you want.

  2. Query value by key

get key

 

  1. Manually update the value of the key
set key value [EX seconds]

 

  1. Delete key
del key

 

Moreredis Client

Redis has rich client support, if you want to get a complete list, you can visit here https://redis.io/clients

Redis command

Redis command collection https://redis.io/commands

Reids document

Redis official document https://redis.io/documentation

Redis download

Redis download

  • Https://redis.io/download: linux
  • Windows: https://github.com/MSOpenTech/redis/releases
End

Can't remember to write something good, remember to write it again, have any questions or questions, please feel free to contact me weihanli@outlook.com

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.