掌握Redis的 Three 基本操作(操作redis)

Nowadays, there are people who are interested in Redis. Thus, I would like to share some basic operations of Redis with you.

Firstly, let’s talk about connecting to Redis. We can connect to it through two ways: IP and port setting. Via the command line, we can type “telnet IP port”, which establishes the connection. We can also use the open source redis-cli command line tool to vector the connection with “redis-cli -h IP -p port” command.

Secondly, let’s talk about the data type. Redis supports five data types: strings, hashes, lists, sets and sorted sets. Each data type uses different methods for storage and manipulation. For example, strings store key-value prs and support bit and string operation commands, while the sets store non-repeating elements and support range and set operation commands, while hashes are the combination of strings and collections and can be used to store filed-value prs.

Thirdly, let’s talk about the basic commands of Redis. The commands are used to store, update and delete data, including set and get commands such as “set key value”, “get key” and so on; hash commands such as “hset key field value”, “hget key field” and so on; list commands such as “lpush key value” and so on; and set commands such as “sadd key value”, “srem key value” and so on.

Finally, in order to control different accesses, Redis provides several commands to manage the users. For example, the “auth” command can be used to execute a login check, while the “select dbname” command can switch the database. In addition, the “expire key time” command and “ttl key” command can be used to manage the timeframe of the key.

All in all, these three basic commands of Redis allow us to manage and manipulate data easily. As we can see, with the knowledge of the connection, the data type, and the basic commands, we can start to master Redis.


数据运维技术 » 掌握Redis的 Three 基本操作(操作redis)