Skip to content

String Commands

Bases: BaseCommand

Mixin for Redis String and binary value commands (e.g. GET, SET, INCR, APPEND).

Source code in pyredis/commands/string.py
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
class String(BaseCommand):
    """Mixin for Redis String and binary value commands (e.g. GET, SET, INCR, APPEND)."""

    def __init__(self):
        super().__init__()

    def append(self, *args):
        if self._cluster:
            return self.execute(
                *[b"APPEND", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"APPEND", *args]
        )

    def bitcount(self, *args):
        if self._cluster:
            return self.execute(
                *[b"BITCOUNT", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"BITCOUNT", *args]
        )

    def bitfield(self, *args):
        if self._cluster:
            return self.execute(
                *[b"BITFIELD", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"BITFIELD", *args]
        )

    def bitop(self, *args):
        if self._cluster:
            return self.execute(
                *[b"BITOP", *args],
                shard_key=args[1]
            )
        return self.execute(
            *[b"BITOP", *args]
        )

    def bitpos(self, *args):
        if self._cluster:
            return self.execute(
                *[b"BITPOS", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"BITPOS", *args]
        )

    def decr(self, *args):
        if self._cluster:
            return self.execute(
                *[b"DECR", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"DECR", *args]
        )

    def decrby(self, *args):
        if self._cluster:
            return self.execute(
                *[b"DECRBY", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"DECRBY", *args]
        )

    def get(self, *args):
        if self._cluster:
            return self.execute(
                *[b"GET", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"GET", *args]
        )

    def getbit(self, *args):
        if self._cluster:
            return self.execute(
                *[b"GETBIT", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"GETBIT", *args]
        )

    def getrange(self, *args):
        if self._cluster:
            return self.execute(
                *[b"GETRANGE", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"GETRANGE", *args]
        )

    def getset(self, *args):
        if self._cluster:
            return self.execute(
                *[b"GETSET", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"GETSET", *args]
        )

    def incr(self, *args):
        if self._cluster:
            return self.execute(
                *[b"INCR", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"INCR", *args]
        )

    def incrby(self, *args):
        if self._cluster:
            return self.execute(
                *[b"INCRBY", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"INCRBY", *args]
        )

    def incrbyfloat(self, *args):
        if self._cluster:
            return self.execute(
                *[b"INCRBYFLOAT", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"INCRBYFLOAT", *args]
        )

    def mget(self, *args):
        if self._cluster:
            return self.execute(
                *[b"MGET", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"MGET", *args]
        )

    def mset(self, *args):
        if self._cluster:
            return self.execute(
                *[b"MSET", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"MSET", *args]
        )

    def msetnx(self, *args):
        if self._cluster:
            return self.execute(
                *[b"MSETNX", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"MSETNX", *args]
        )

    def psetex(self, *args):
        if self._cluster:
            return self.execute(
                *[b"PSETEX", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"PSETEX", *args]
        )

    def set(self, *args):
        if self._cluster:
            return self.execute(
                *[b"SET", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"SET", *args]
        )

    def setbit(self, *args):
        if self._cluster:
            return self.execute(
                *[b"SETBIT", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"SETBIT", *args]
        )

    def setex(self, *args):
        if self._cluster:
            return self.execute(
                *[b"SETEX", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"SETEX", *args]
        )

    def setnx(self, *args):
        if self._cluster:
            return self.execute(
                *[b"SETNX", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"SETNX", *args]
        )

    def setrange(self, *args):
        if self._cluster:
            return self.execute(
                *[b"SETRANGE", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"SETRANGE", *args]
        )

    def strlen(self, *args):
        if self._cluster:
            return self.execute(
                *[b"STRLEN", *args],
                shard_key=args[0]
            )
        return self.execute(
            *[b"STRLEN", *args]
        )

__init__()

Source code in pyredis/commands/string.py
7
8
def __init__(self):
    super().__init__()

append(*args)

Source code in pyredis/commands/string.py
10
11
12
13
14
15
16
17
18
def append(self, *args):
    if self._cluster:
        return self.execute(
            *[b"APPEND", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"APPEND", *args]
    )

bitcount(*args)

Source code in pyredis/commands/string.py
20
21
22
23
24
25
26
27
28
def bitcount(self, *args):
    if self._cluster:
        return self.execute(
            *[b"BITCOUNT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"BITCOUNT", *args]
    )

bitfield(*args)

Source code in pyredis/commands/string.py
30
31
32
33
34
35
36
37
38
def bitfield(self, *args):
    if self._cluster:
        return self.execute(
            *[b"BITFIELD", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"BITFIELD", *args]
    )

bitop(*args)

Source code in pyredis/commands/string.py
40
41
42
43
44
45
46
47
48
def bitop(self, *args):
    if self._cluster:
        return self.execute(
            *[b"BITOP", *args],
            shard_key=args[1]
        )
    return self.execute(
        *[b"BITOP", *args]
    )

bitpos(*args)

Source code in pyredis/commands/string.py
50
51
52
53
54
55
56
57
58
def bitpos(self, *args):
    if self._cluster:
        return self.execute(
            *[b"BITPOS", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"BITPOS", *args]
    )

decr(*args)

Source code in pyredis/commands/string.py
60
61
62
63
64
65
66
67
68
def decr(self, *args):
    if self._cluster:
        return self.execute(
            *[b"DECR", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"DECR", *args]
    )

decrby(*args)

Source code in pyredis/commands/string.py
70
71
72
73
74
75
76
77
78
def decrby(self, *args):
    if self._cluster:
        return self.execute(
            *[b"DECRBY", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"DECRBY", *args]
    )

execute(*args, **kwargs)

Source code in pyredis/commands/base.py
5
6
def execute(self, *args, **kwargs):
    raise NotImplementedError

get(*args)

Source code in pyredis/commands/string.py
80
81
82
83
84
85
86
87
88
def get(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GET", *args]
    )

getbit(*args)

Source code in pyredis/commands/string.py
90
91
92
93
94
95
96
97
98
def getbit(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GETBIT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GETBIT", *args]
    )

getrange(*args)

Source code in pyredis/commands/string.py
100
101
102
103
104
105
106
107
108
def getrange(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GETRANGE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GETRANGE", *args]
    )

getset(*args)

Source code in pyredis/commands/string.py
110
111
112
113
114
115
116
117
118
def getset(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GETSET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GETSET", *args]
    )

incr(*args)

Source code in pyredis/commands/string.py
120
121
122
123
124
125
126
127
128
def incr(self, *args):
    if self._cluster:
        return self.execute(
            *[b"INCR", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"INCR", *args]
    )

incrby(*args)

Source code in pyredis/commands/string.py
130
131
132
133
134
135
136
137
138
def incrby(self, *args):
    if self._cluster:
        return self.execute(
            *[b"INCRBY", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"INCRBY", *args]
    )

incrbyfloat(*args)

Source code in pyredis/commands/string.py
140
141
142
143
144
145
146
147
148
def incrbyfloat(self, *args):
    if self._cluster:
        return self.execute(
            *[b"INCRBYFLOAT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"INCRBYFLOAT", *args]
    )

mget(*args)

Source code in pyredis/commands/string.py
150
151
152
153
154
155
156
157
158
def mget(self, *args):
    if self._cluster:
        return self.execute(
            *[b"MGET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"MGET", *args]
    )

mset(*args)

Source code in pyredis/commands/string.py
160
161
162
163
164
165
166
167
168
def mset(self, *args):
    if self._cluster:
        return self.execute(
            *[b"MSET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"MSET", *args]
    )

msetnx(*args)

Source code in pyredis/commands/string.py
170
171
172
173
174
175
176
177
178
def msetnx(self, *args):
    if self._cluster:
        return self.execute(
            *[b"MSETNX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"MSETNX", *args]
    )

psetex(*args)

Source code in pyredis/commands/string.py
180
181
182
183
184
185
186
187
188
def psetex(self, *args):
    if self._cluster:
        return self.execute(
            *[b"PSETEX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"PSETEX", *args]
    )

set(*args)

Source code in pyredis/commands/string.py
190
191
192
193
194
195
196
197
198
def set(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SET", *args]
    )

setbit(*args)

Source code in pyredis/commands/string.py
200
201
202
203
204
205
206
207
208
def setbit(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SETBIT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SETBIT", *args]
    )

setex(*args)

Source code in pyredis/commands/string.py
210
211
212
213
214
215
216
217
218
def setex(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SETEX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SETEX", *args]
    )

setnx(*args)

Source code in pyredis/commands/string.py
220
221
222
223
224
225
226
227
228
def setnx(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SETNX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SETNX", *args]
    )

setrange(*args)

Source code in pyredis/commands/string.py
230
231
232
233
234
235
236
237
238
def setrange(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SETRANGE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SETRANGE", *args]
    )

strlen(*args)

Source code in pyredis/commands/string.py
240
241
242
243
244
245
246
247
248
def strlen(self, *args):
    if self._cluster:
        return self.execute(
            *[b"STRLEN", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"STRLEN", *args]
    )