redis-stringタイプコマンド操作ノート


redis-stringタイプ
コマンド#コマンド#
1.付与と取値
SET key value #   

GET key       #   

2.増分数
INCR num

3.指定した整数を増やす
`INCRBY`   `INCR`      ,         `increment`           , :


redis> INCRBY bar 2
(integer) 2
redis> INCRBY bar 3
(integer) 5

4.指定した整数を減らす
DECR key

DECRBY key decrement

5.指定浮動小数点数を増やす
INCRBYFLOAT key increment

redis> INCRBYFLOAT bar 2.7
"6.7"
redis> INCRBYFLOAT bar 5E+4
"50006.69999999999999929"

6.末尾への追加値
APPEND key value

APPEND           value。               value,    SET key value。              。 :

redis> SET key hello
OK
redis> APPEND key " world!"
(integer) 12

  key   "hello world!"。APPEND             ,          , redis-cli            。

 
7.文字列長の取得
STRLEN key

STRLEN         ,         0。  :

redis> STRLEN key
(integer) 12
redis> SET key   
OK
redis> STRLEN key
(integer) 6

                   ,               。   Redis       UTF-8     ,  “ ” “ ”    UTF-8       3,        6。

8.複数のキー値の同時取得/設定
MGET key [key …]


MSET key value [key value …]

MGET/MSET GET/SET  ,  MGET/MSET      /        。  :

redis> MSET key1 v1 key2 v2 key3 v3
OK
redis> GET key2
"v2"
redis> MGET key1 key3
1) "v1"
2) "v3"

9.ビット操作
GETBIT key offset

SETBIT key offset value

BITCOUNT key [start] [end]

BITOP operation destkey key [key …]

     8       ,Redis   4                。    ,     foo    bar:

redis> SET foo bar
OK

bar 3   “b”“a” “r”   ASCII    98、97 114,          1100010、1100001 1110010,

GETBIT                         (0 1),   0  :

redis> GETBIT foo 0
(integer) 0
redis> GETBIT foo 6
(integer) 1

                                   0:

redis> GETBIT foo 100000
(integer) 0


SETBIT                       ,          。     foo     aar,        foo          6   0, 7   1:

redis> SETBIT foo 6 0
(integer) 1
redis> SETBIT foo 7 1
(integer) 0
redis> GET foo
"aar"


                     ,SETBIT                0,                                0:

redis> SETBIT nofoo 10 1
(integer) 0
redis> GETBIT nofoo 5
(integer) 0

BITCOUNT               1       ,  :


redis> BITCOUNT foo
(integer) 10

                ,             ( "aa"):
redis> BITCOUNT foo 0 1
(integer) 6



BITOP                  ,       destkey       。BITOP          AND、OR、XOR NOT。      bar aar  OR  :


redis> SET foo1 bar
OK
redis> SET foo2 aar
OK
redis> BITOP OR res foo1 foo2
(integer) 3
redis> GET res
"car"




Redis 2.8.7   BITPOS  ,              0  1   。   “bar”      ,                 1    ,     :



redis> SET foo bar
OK
redis> BITPOS foo 1
(integer) 1

  BITPOS       ,“bar”       1          1(       ,BITPOS        0    )。                   ?BITPOS                            (   0    )     。              ,    。                    ( “a” “r”)        1         ,     :

redis> BITPOS foo 1 1 2
(integer) 9


                   ,       。                                     1,       0         ,                    。    Redis                0。

                   。                    ID,                           (  ID    ,     1 0       ),    100           100 KB    ,    GETBIT SETBIT        O(1),             。


  :
  SETBIT   ,                         ,Redis                                  0。          ,                             。    ,   2014  MacBook Pro    ,     232-1  (   500 MB   )      1    。                  ,        。                ,         ID  100000001   ,     10 MB   ,            ID  100000000     。


参照リンク:https://www.jianshu.com/p/86eee4c13645
ブックマーク:ハッシュ・タイプ