In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
In the usual work, we need to do some operations on the Redis database according to the requirements.
You can refer to Redis's official website http://redis.io/commands for more information.
1.SELECT switch database
Redis 127.0.0.1 group 6379 [1] > HELP SELECT SELECT index summary: Change the selected database for the current connection since: 1.0.0 group: connection redis 127.0.0.1 group [1] > SELECT 2OK
2.LLEN gets the length of a list
Redis 127.0.0.1 group 6379 [2] > HELP LLEN LLEN key summary: Get the length of a list since: 1.0.0 group: list redis 127.0.0.1 list redis 6379 [2] > LLEN bi (integer) 412
3.LRANGE gets all the elements of a list
The LRANGE index starts with 0, 0 for the first element, and-1 for the last element
LRANGE key start stop summary: Get a range of elements from a list since: 1.0.0 group: list redis 127.0.1 group 6379 [2] > LRANGE bi 0 5
4.LPUSH adds one or more values to the beginning of a list
Redis 127.0.0.1 value 6379 [2] > HELP LPUSH LPUSH key value [value...] Summary: Prepend one or multiple values to a list since: 1.0.0 group: list redis 127.0.0.1 list redis [2] > LPUSH bi http://abc.com/logUserLogin?event_id=25&uid=de721bcef5cba1fc182d18
5.RPUSH appends one or more values to the end of a list
Redis 127.0.0.1 value 6379 [2] > HELP RPUSH RPUSH key value [value...] Summary: Append one or multiple values to a list since: 1.0.0 group: list redis 127.0.0.1 list redis [2] > RPUSH bi http://abc.com/logUserLogin?event_id=25&uid=de721bcef5cba1fc182d18
6.SAVE synchronizes data to disk
The connection is blocked when the SAVE command is executed, so the build environment is best to use the BGSAVE command
Redis 127.0.0.1 group 6379 [2] > HELP SAVE SAVE-summary: Synchronously save the dataset to disk since: 1.0.0 group: server redis 127.0.0.1 Synchronously save the dataset to disk since 6379 [2] > SAVEOK (1.33s)
7.BGSAVE asynchronous data to disk
Using BGSAVE,Redis will save data in the background, without affecting the normal client connection, Redis will fork a child process to save data, and the parent process will continue to process client requests.
Redis 127.0.0.1 Asynchronously save the dataset to disk since 6379 [2] > HELP BGSAVE BGSAVE-summary: Asynchronously save the dataset to disk since: 1.0.0 group: server redis 127.0.0.1 Asynchronously save the dataset to disk since 6379 [2] > BGSAVEBackground saving started
8.TYPE determines the type of a KEY
Redis 127.0.0.1 group 6379 [2] > HELP TYPE TYPE key summary: Determine the type stored at key since: 1.0.0 group: generic redis 127.0.0.1 group [2] > TYPE bilist
9.BGREWRITEAOF
Rewrite the AOF file asynchronously, and Redis will create a version of AOF that is optimized for the current AOF file.
Redis 127.0.0.1 group 6379 > help BGREWRITEAOF BGREWRITEAOF-summary: Asynchronously rewrite the append-only file since: 1.0.0 group: server
10.CONFIG GET
Get the value of a configuration item
Redis 127.0.0.1 group 6379 > help config get CONFIG GET parameter summary: Get the value of a configuration parameter since: 2.0.0 group: server redis 127.0.1 group 6379 > config get maxmemory1) "maxmemory" 2) "0"
11.CONFIG SET
Set the value of a parameter
Redis 127.0.0.1 group 6379 > help config set CONFIG SET parameter value summary: Set a configuration parameter to the given value since: 2.0.0 group: server redis 127.0.0.1 group 6379 > config set maxmemory 200000000OK
12.DBSIZE
Returns the number of KEY worth of the current database
Redis 127.0.0.1 group 6379 [3] > HELP DBSIZE DBSIZE-summary: Return the number of keys in the selected database since: 1.0.0 group: server redis 127.0.0.1 group [3] > dbsize (integer) 12502
13.DEL
Delete a key value
Redis 127.0.0.1 key 6379 > help del DEL key [key...] Summary: Delete a key since: 1.0.0 group: generic redis 127.0.0.1 group 6379 > del foo (integer) 1
14.EXISTS
Check whether a KEY exists
Redis 127.0.0.1 group 6379 > help exists EXISTS key summary: Determine if a key exists since: 1.0.0 group: generic redis 127.0.1 group 6379 > exists foo (integer) 1
15.SET command
Set a KEY value
Redis 127.0.0.1 group 6379 > help set SET key value summary: Set the string value of a key since: 1.0.0 group: string redis 127.0.1 group 6379 > set foo testOKredis 127.0.1
16.PERSIST
Delete the expiration time of a KEY
Edis 127.0.0.1 group 6379 > help persist PERSIST key summary: Remove the expiration from a key since: 2.2.0 group: generic
17.RENAME
Rename a KEY
Redis 127.0.0.1 group 6379 > help rename RENAME key newkey summary: Rename a key since: 1.0.0 group: generic redis 127.0.1 group 6379 > rename foo footestOKredis 127.0.1
18.EXPIRE
Set a TTL expiration time for a KEY
Redis 127.0.0.1 group 6379 > help expire EXPIRE key seconds summary: Set a key's time to live in seconds since: 1.0.0 group: generic redis 127.0.1 group 6379 > expire footest 300 (integer) 1
19.TTL
Get expiration time
Redis 127.0.0.1 generic redis 6379 > help ttl TTL key summary: Get the time to live for a key since: 1.0.0 group: generic redis 127.0.0.1 generic redis 6379 > ttl footest (integer) 289redis 127.0.0.1 Get the time to live for a key since 6379 > ttl footest (integer) 285redis 127.0.0.1 ttl footest (integer) 283redis 127.0.0.16379 > ttl footest (integer) 282redis 127.0.0.16379 > ttl footest (integer) 282redis 127.0.0.1
20.EXPIREAT
Sets the expiration time of a KEY, expressed as a UNIX timestamp
Redis 127.0.0.1 redis 6379 > help expireat EXPIREAT key timestamp summary: Set the expiration for a key as a UNIX timestamp since: 1.2.0 group: generic redis 127.0.0.1 generic redis 6379 > expireat foo 1431532800 (integer) 1redis 127.0.0.1 Set the expiration for a key as a UNIX timestamp since 6379 > ttl foo (integer) 3210141
21.GET
Get the value of a KEY
Redis 127.0.0.1 group 6379 > help get GET key summary: Get the value of a key since: 1.0.0 group: string redis 127.0.1 group 6379 > get foo "test"
22.HGET
Get the value of a hash field
Redis 127.0.0.1 redis 6379 > help hget HGET key field summary: Get the value of a hash field since: 2.0.0 group: hash redis 127.0.0.1 hash redis 6379 > hset myhash field1 "foo" (integer) 1redis 127.0.0.1 foo > hget myhash field2 (nil) redis 127.0.1
23.LASTSAVE
UNIX timestamp of the last time the data was successfully saved to disk
Redis 127.0.0.1 redis 6379 > help lastsave LASTSAVE-summary: Get the UNIX time stamp of the last successful save to disk since: 1.0.0 group: server redis 127.0.0.1 group 6379 > lastsave (integer) 1428373205redis 127.0.0.1 summary 6379 >
24.LPUSH
Append one or more values to a Redis list
Redis 127.0.0.1 value 6379 > help lpush LPUSH key value [value...] Summary: Prepend one or multiple values to a list since: 1.0.0 group: list redis 127.0.0.1 list redis 6379 > lpush mylist a b c (integer) 6redis 127.0.0.1 group 6379 > LRANGE mylist 0-11) "c" 2) "b" 3) "a" 4) "c" 5) "b" 6) a "redis 127.0.0.1 list redis 6379 > llen mylist (integer) 6
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.