getrange

1. 基本語法

getrange(key , start, end, callback)

回傳key對應字符串的截取內容,字符串的截取範圍由 startend 兩個偏移量决定(包括 startend 在内)。

2. 範例

(1) 英數字的字符串擷取

client.set('mykey', 'this is aiii console');
client.getrange('mykey', 0, 3, redis.print); 

index

0

1

2

3

4

5

6

...

char

t

h

i

s

i

s

...

Reply: this

(2) 中文字符串擷取

client.set('mykey', '這裡是Aiii');
client.getrange('mykey', 0, 3, redis.print); 

index

0

1

2

3

4

5

...

UTF-8(HEX)

0xe9

0x80

0x99

0xe8

0xa3

0xa1

...

char

...

Reply: 這�

Tag : substring slice extract

Last updated

Was this helpful?