Introduction to redis and common commands
Introduction to redis
Redis is an open source, BSD-licensed, key-value caching and storage system.Because Redis's keys include string, hash, list, set, sorted set, bitmap, and hyperloglog, they are often referred to as data structure servers.You can run atomic operations on these types, such as appending strings, increasing values in hashes, adding an element to a list, calculating the intersection, union, and difference of sets, or getting the highest ranked element from an ordered set.
For high performance, Redis uses in-memory datasets.Depending on your usage scenario, you can dump the dataset to disk at regular intervals or append each command to the log to persist.Persistence can also be disabled if you just need a feature-rich, networked memory cache.
Redis also supports master-slave asynchronous replication, very fast non-blocking initial synchronization, and automatic reconnection to local resynchronization when the network is disconnected.Other features include:
- affair
- Subscription/Publication
- Lua script
- Key with TTL
- LRU Recycling Keys
- Automatic failover
You can use Redis in many languages.
Redis is written in the ANSI C language and runs on most POSIX systems, such as Linux, *BSD, OS X, without additional dependency.Redis is developed and fully tested on both Linux and OS X operating systems, and we recommend Linux as a deployment environment.Redis can also run on Solaris-derived systems, such as SmartOS, but support needs to be enhanced.There is no officially supported build version of Windows, but Microsoft has developed and maintained a 64-bit version of Windows.
More about:
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.
redis configuration
linux configuration
linux Download Installation Reference Official Web https://redis.io/download
windows configuration
The redis website does not provide support for Windows, but Microsoft's open source team did a Windows version of the project address: https://github.com/MSOpenTech/redis Now I want to sigh, Microsoft is great!!!
From here https://github.com/MSOpenTech/redis/releases Download the redis Windows version, I want to recall here that I last configured it with version 2.4.5, which also needs to execute commands manually to install services, manually configure environment variables. Now everything is automated. After installation, services are automatically installed and installed, you can chooseIt is really much easier to add the installation directory to the environment variable.
After downloading the latest release installation package, you can unpack the installation and add it to the environment variable.
Common commands for redis
Connect to 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
- -p port number (default port number is 6379)
- -a Access Password (password access is not required by default, requirepass node of redis.conf can be modified if password is set)
basic operation
Note: Command names are case insensitive, key s and value s are case sensitive
1 # Select database, use by default index 0 database 2 SELECT index 3 4 # Getting in Cache key 5 # View all in the cache key 6 KEYS * 7 8 # Fuzzy Match Query Cache key 9 KEYS aa* 10 KEYS *aaa 11 KEYS aa*bb 12 13 # judge key Is it there 14 EXISTS key [key...] 15 16 # Return Value Description 17 # - 1: existence 18 # - 0: Non-existent 19 20 # according to key Obtain value 21 GET key 22 23 # Return Value Description 24 # - (nil): key Non-existent 25 26 # according to key Obtain value Of substring 27 GETRANGE key start end 28 29 # To update key Of value Return to Old value 30 GETSET key value 31 32 # Get multiple at once key Value of 33 MGET key [key ...] 34 35 # Set up/Update Cached Value 36 SET key value [EX seconds] [PX milliseconds] [NX|XX] 37 38 # Parameter Description 39 # - EX : Set expiration time in seconds 40 # - PX : Set expiration time in milliseconds 41 # - NX : only key Set when nonexistent key Of value 42 # - XX : only key Set when present key Of value 43 44 SET key value PX milliseconds 45 SET key value EX seconds NX 46 SET key value XX 47 48 # only key Set if it does not exist, and `SET key value NX`The effect is the same 49 SETNX key value 50 51 # Rewrite key Corresponding value Part of 52 SETRANGE key offset value 53 54 # Obtain key Corresponding value Length 55 STRLEN key 56 57 # according to key Delete values from cache 58 DEL key [key...] 59 60 # integer Value of type minus one 61 DECR key 62 63 # integer Type Value Decrease decrement 64 DECRBY key decrement 65 66 # integer Value of type plus one 67 INCR key 68 69 # integer Type Value Decrease increment 70 INCRBY key increment
More key operations
1 # Set in seconds key Expiration Time 2 EXPIRE key seconds 3 4 # Set in seconds key Expired UNIX time stamp 5 EXPIREAT key timestamp 6 7 # Set in milliseconds key Expiration Time 8 PEXPIRE key milliseconds 9 10 # Set in milliseconds key Expired UNIX time stamp 11 PEXPIREAT key milliseconds-timestamp 12 13 # move key To another database 14 MOVE key db 15 16 # remove key Expiration time, set to no expiration 17 PERSIST key 18 19 # Obtain key The remaining time to live is in seconds, and how long to expire is in seconds 20 TTL key 21 22 #Return Value Description 23 # -2: key Non-existent 24 # -1: key Exists but no expiration time is set 25 26 # Obtain key The remaining time to live is in milliseconds and how long to expire in milliseconds 27 PTTL key 28 29 # Get a randomly generated key 30 RANDOMKEY 31 32 # Rename one key 33 RENAME key newkey 34 35 # Obtain key Stored value Data type 36 TYPE key 37 38 # list or set sort 39 SORT key
More Commands
More References https://redis.io/commands
Remote Redis Debugging
- Connect to remote redis server
# Anonymous Access redis-cli -h 172.16.20.233 -p 6479 # Password Access redis-cli -h 172.16.20.233 -p 6479 -a p@ssword
- Using keys fuzzy query, query the full name of the key
# with aaa Ending key keys *aaa # with aaa initial key keys aaa* # Completely Fuzzy Matching Inclusion aaa Of key keys *aaa*
-
Find the key you want, copy the full key name, and if you return (empty list or set), there is no such key, check that your pattern is correct, and if it is correct, there is no key you want
-
Query value based on key
get key
- Manually update the value of the key
set key value [EX seconds]
- Delete key
del key
More
redis client
redis has rich client support, and if you want a complete list, you can visit here https://redis.io/clients
redis command
redis command collection https://redis.io/commands
reids document
Official redis document https://redis.io/documentation
redis Download
redis Download
- linux : https://redis.io/download
- windows : https://github.com/MSOpenTech/redis/releases
End
I can't think of anything to write about. Come back and write again. If you have any questions or questions, feel free to contact me at any time. weihanli@outlook.com