memcached Installation and connection
Start with Docker: Docker run-p 11211:11211-d--name memcached memcached
To connect using telnet: Telnet 10.141.4.25 11211
Common Operations Store Command set
set key flags exptime bytes [noreply]
value
Example:
set mykey 05005
relax
Add
add key flags exptime bytes [noreply]
value
Example:
add newkey 04009
memcached
Replace
replace key flags exptime bytes [noreply]
value
Example:
replace newkey 04005
sleep
prepend
prepend key flags exptime bytes [noreply]
value
Example:
prepend newkey 04006
go to
Append
append key flags exptime bytes [noreply]
value
Example:
append newkey 04003
ok?
CAs
cas key flags exptime bytes unique_cas_token [noreply]
value
Find command get
get key
get key1 key2 key3
Gets
gets key
gets key1 key2 key3
Delete
Delete key [noreply]incr
incr key increment_value
DECR
decr key increment_value
Statistics CommandStats
Used to return statistical information such as PID (process number), version number, number of connections, and so on.
Stats itemsstats slabssitats Sizesflush_alljava connection memcached
Depend on:
<dependency>
<groupId>net.spy</groupId>
<artifactId>spymemcached</artifactId>
<version>2.12.1</version>
</dependency>
R Edis
Brief introduction
A high-performance Key-value database. Supports the persistence of data and supports Key-value,list,set,zset,hash storage. It is commonly referred to as a data structure server because the value (values) can be of five data types: string (string), hash (hash), list, set (set), and Zset (sorted set: Ordered set).
Read 110,000 times/s, write 81,000/s.
Installation and connection
Docker run-d-P 6361:6379--name Redis Redis
Redis-cli-h 10.127.12.16-p 6361
Common operations String
# String String
SET key value // Associates a string value with a key.
EXPIRE key seconds // Set the survival time in seconds.
TTL key // Remaining survival time.
SETRANGE key offset value // Overwrite the string value stored in the given key with the value parameter, starting from the offset.
SETEX key seconds value // Associate the value value to the key and set the key's lifetime to seconds (in seconds).
MSET key value [key value ...] // Set one or more key-value pairs at the same time.
MSETNX key value [key value ...] // Set one or more key-value pairs at the same time, if and only if the key does not exist.
APPEND key value // If the key already exists and is a string, the APPEND command appends the value to the original value of the key. Add if it doesn't exist.
GET key // Returns the string value associated with the key.
MGET key [key ...] // Returns all (one or more) values of the given key.
GETRANGE key start end // Returns the substring of the string value in key. The interception range of the string is determined by the offsets of start and end (including start and end).
GETSET key value // Set the value of the given key to value and return the old value of the key.
STRLEN key // Returns the length of the string value stored by key.
DECR key // Decrement the numeric value stored in key by one.
DECRBY key decrement // Decrement the value stored by key by decrement.
INCR key // Increment the numerical value stored in key by one.
INCRBY key increment // Increment the value stored by key.
SETBIT key offset value // Set or clear the bit at the specified offset for the string value stored by key.
GETBIT key offset // For the string value stored by key, get the bit at the specified offset.
Hash
# Hash table
HSET key field value // Set the value of the field in the hash table key to value.
HSETNX key field value // Set the value of the field in the hash table key to value if and only if the field does not exist.
HMSET key field value [field value ...] // Set multiple field-value pairs into the hash table key at the same time.
HGET key field // Get the value of the field of the hash table key.
HMGET key field [field ...] // Colleagues get the values of multiple fields of multiple hash table keys.
HGETALL key // Return all fields and values in the hash table key.
HDEL key field [field ...] // Delete one or more specified fields in the hash table key. Non-existent fields will be ignored.
HLEN key // Returns the number of fields in the hash table key.
HEXISTS key field // Check whether the given field exists in the hash table key.
HINCRBY key field increment // Add the increment to the value of the field in the hash table key.
HKEYS key // Returns all fields in the hash table key.
HVALS key // Returns all values in the hash table key.
List
# Lish 表
LPUSH key value [value ...] // Insert one or more values into the head of the list key.
LPUSHX key value // Insert the value value into the head of the list key if and only if the key exists and is a list. When the key does not exist, the LPUSHX command does nothing.
RPUSH key value [value ...] // Insert one or more values into the end of the list key.
RPUSHX key value // Insert the value into the end of the list key if and only if the key exists and is a list. When the key does not exist, the RPUSHX command does nothing.
LPOP key // Remove and return the head element of the list key.
RPOP key // Remove and return the tail element of the list key.
BLPOP key [key ...] timeout // is the blocking popup primitive of the list. When there are no elements in the given list to pop up, the connection will be blocked by the BLPOP command until the waiting timeout or discovery is available. Until the element pops up.
BRPOP key [key ...] timeout // is the blocking popup primitive of the list. When there is no element in the given list to pop up, the connection will be blocked by the BLPOP command until the waiting timeout or discovery is available. Until the element pops up.
LLEN key // Returns the length of the list key.
LRANGE key start stop // Returns the elements in the specified interval in the list key. The interval is specified by the offsets start and stop.
LREM key count value // Remove the elements in the list that are equal to the parameter value. Count> 0, search from the beginning of the table to the end of the table, remove the elements equal to value, the number is count. count = 0, delete all.
LSET key index value // The value of the element whose index is the index of the list key is even value.
LTRIM key start stop // Trim a list, that is, let the list retain only the elements within the specified interval, and elements that are not within the specified interval will be deleted.
LINDEX key index // Returns the elements in the list key whose index is index.
LINSERT key BEFORE | AFTER pivot value // Insert the value value into the list key, before or after the value pivot.
RPOPLPUSH source destination // Pop the last element (tail element) in the list source and return it to the client. Insert the element popped by source into the destination list as the head element of the destination list.
BRPOPLPUSH source destination timeout // is the blocking version of RPOPLPUSH. When the given list source is not empty, BRPOPLPUSH behaves the same as RPOPLPUSH.
Set
#Collection basics
A = {'a', 'b', 'c'}
B = {'a', 'e', 'i', 'o', 'u'}
inter (x, y): Intersection, an element that exists in both set x and y.
inter (A, B) = {'a'}
union (x, y): union, the elements in the set x or y, if an element appears in both x and y, then only record once.
union (A, B) = {'a', 'b', 'c', 'e', 'i', 'o', 'u'}
diff (x, y): difference set, elements in set x but not in set y.
diff (A, B) = ('b', 'c')
card (x): cardinality, the number of elements in a collection.
card (A) = 3
Empty set: A set with a cardinality of zero.
#Set
SADD key member [member ...] // Add one or more member elements to the collection key. Member elements that already exist in the collection will be ignored.
SREM key member [member ...] // Remove one or more member elements from the set key. Non-existent member elements are ignored.
SMEMBERS key // Returns all members in the collection key. .
SISMEMBER key member // Determine whether the member element is a member of the collection key.
SCARD key // Returns the cardinality of the collection key (the number of elements in the collection).
SMOVE source destination member // Move the member element from the source collection to the destination collection.
SPOP key // Remove and return a random element from the collection.
SRANDMEMBER key // Returns a random element in the collection.
SINTER key [key ...] // Returns the intersection of the given set.
SINTERSTORE destination key [key ...] // This command is equivalent to SINTER, but it saves the result to the destination collection instead of simply returning the result set.
SUNION key [key ...] // Return the union of the given set.
SUNIONSTORE destination key [key ...] // This command is equivalent to SUNION, but it saves the result to the destination collection, instead of simply returning the result set.
SDIFF key [key ...] // Return the difference of all given sets.
SDIFFSTORE destination key [key ...] // This command is equivalent to SDIFF, but it saves the result to the destination collection instead of simply returning the result set.
Zset
#Sorted Set
ZADD key score member [[score member] [score member] ...] // Add one or more member elements and their score values to the ordered set key. The score value can be an integer value or a double-precision floating-point number.
ZREM key member [member ...] // Remove one or more members in the ordered set key. Non-existent members will be ignored.
ZCARD key // Returns the cardinality of the ordered set key.
ZCOUNT key min max // Returns the members of the ordered set key with score values between min and max (the default includes score values equal to min or max).
ZSCORE key member // Returns the score value of member member in the ordered set key.
ZRANGE key start stop [WITHSCORES] // Returns members in the specified range in the ordered set key.
ZREVRANGE key start stop [WITHSCORES] // Returns the members in the specified interval in the ordered set key, and the positions of the members are arranged according to the score value decreasing (large to small).
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count] // Returns all members in the ordered set key whose score values are between min and max (including equal to min or max). The members of the ordered set are ranked in ascending (small to large) score value.
ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count] // Returns all members of the ordered set key whose score value is between max and min (the default includes equal to max or min). The members of the ordered set are arranged in descending order of score value (large to small).
ZRANK key member // Returns the rank of member member in the ordered set key. The members of the ordered set are arranged in ascending order of score value (from small to large).
ZREMRANGEBYRANK key start stop // Remove all members in the ordered rank key from the ordered set key.
ZREMRANGEBYSCORE key min max // Remove all members in the ordered set key with score values between min and max (including equal to min or max).
ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM | MIN | MAX]
// Calculate the intersection of a given one or more ordered sets, where the number of given keys must be specified with the numkeys parameter, and store the intersection (result set) to destination.
ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM | MIN | MAX]
// Calculate the union of a given one or more ordered sets, where the number of given keys must be specified with the numkeys parameter, and store the union (result set) to destination.
Memcached & Redis Basic Operations