II-3 Strings

II-3 Strings
20 common commands of String:
    set key value
	    Note: Chinese garbled set get has not been resolved? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
		If you want to use Chinese in redis-cli, you must open the --raw option to display Chinese normally
		[root@mongodba logs]# redis-cli  --raw
		illustrate:
			An English character only needs to use a single byte to store, while a Chinese character needs to use multiple bytes to store.
			We all know that the indexes used by setrange and getrange in Redis are arranged according to bytes rather than characters, and they will only be used in
			It can only be used normally when the character is a single byte, and when we store characters represented by multiple bytes like Chinese, these commands are not easy to use.

    get key
    getrange intercepts the string range, note that it starts from 0, if you want to intercept all, it is getrange key 0 -1
			 Example: getrange mykey 0 0 intercepts the first character
			       getrange mykey 0 -1 intercept all characters
	getset sets the value of the specified key and returns the old value of the key				 
			 Example: getset mykey "world"
			 
	getbit key offset: Get the bit at the specified offset.		 
	setbit key offset value: Sets or clears the bit at the specified offset for the string value stored in the key.				 
        Description: It is to convert the value corresponding to the key to byte, that is, the binary type. For example, the ASCII code of 'a' is 97. Converted to binary is: 01100001
              offset 0 counts the first bit in binary from left to right
              offset 2 counts the third digit from left to right
              getbit is to get the value of the corresponding offset in binary (either 0 or 1)			  
			  setbit sets the corresponding offset value in binary to 0 or 1		 
			  bitcount gets how many 1s there are in the corresponding binary on the key

	mget key1 key2 returns the values ​​corresponding to different keys
					 
	setex key timeout value: set the value and its expiration time for the specified key				 
    setnx key value: Set the value of the key only when the key does not exist.				 
	
    The setrange command overwrites the string value stored at the given key with the specified string, starting at offset offset.	
					 
					 
					 

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324648502&siteId=291194637