Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Setting method and steps of key in redis

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The Redis SET command sets the value of a given key. If key already stores other values, SET overwrites the old values, regardless of type.

The basic syntax for redis SET commands is as follows:

Redis 127.0.0.1 6379 > SET KEY_NAME VALUE

Return value:

In previous versions of Redis2.6.12, the SET command always returned OK.

Starting from the Redis2.6.12 version, SET returns OK only when the setting operation is completed successfully.

Example:

Create a key in redis and set the value.

# set redis 127.0.0.1 for keys that do not exist > SET key "value" OK redis 127.0.0.1 for OK redis 6379 > GET key "value" # for keys that do not exist, set redis 127.0.0.1 for OK redis 6379 > SET key "new-value" OK redis 127.0.0.1 for GET key "new-value"

The Redis key command is used to manage the keys of redis.

The basic syntax of the Redis command is as follows:

Redis 127.0.0.1 6379 > COMMAND KEY_NAME

Example:

Redis 127.0.0.1 SET runoobkey redisOKredis 6379 > DEL runoobkey (integer) 1

In the above example, DEL is a command and runoobkey is a key. If the key is deleted successfully, output (integer) 1 after the command is executed, otherwise (integer) 0

Basic commands related to the Redis key:

1 、 DEL key

This command is used to delete the key when the key exists.

2 、 DUMP key

Serializes the given key and returns the serialized value.

3 、 EXISTS key

Check whether the given key exists.

4 、 EXPIRE key seconds

Sets the expiration time in seconds for a given key.

5 、 EXPIREAT key timestamp

EXPIREAT is similar to EXPIRE in that it is used to set the expiration time for key. The difference is that the time parameter accepted by the EXPIREAT command is the UNIX timestamp (unix timestamp).

6 、 PEXPIRE key milliseconds

Sets the expiration time of key in milliseconds.

7 、 PEXPIREAT key milliseconds-timestamp

Sets the timestamp (unix timestamp) of key expiration time in milliseconds

8 、 KEYS pattern

Find all key that match the given pattern (pattern).

9 、 MOVE key db

Move the key of the current database to the given database db.

10 、 PERSIST key

Remove the expiration time of key, and key will persist.

11 、 PTTL key

Returns the remaining expiration time of the key in milliseconds.

12 、 TTL key

Returns the remaining time to live (TTL, time to live) for a given key in seconds.

13 、 RANDOMKEY

A key is randomly returned from the current database.

14 、 RENAME key newkey

Modify the name of key

15 、 RENAMENX key newkey

Rename key to newkey only if newkey does not exist.

16 、 TYPE key

Returns the type of value stored by key.

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report