[MM-19153] Add server version check in helper methods for plugins (#12675)
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
a39f4f1064
Коммит
14b1777959
@@ -11,6 +11,11 @@ import (
|
||||
|
||||
// KVSetJSON implements Helpers.KVSetJSON.
|
||||
func (p *HelpersImpl) KVSetJSON(key string, value interface{}) error {
|
||||
err := p.ensureServerVersion("5.2.0")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -26,9 +31,14 @@ func (p *HelpersImpl) KVSetJSON(key string, value interface{}) error {
|
||||
|
||||
// KVCompareAndSetJSON implements Helpers.KVCompareAndSetJSON.
|
||||
func (p *HelpersImpl) KVCompareAndSetJSON(key string, oldValue interface{}, newValue interface{}) (bool, error) {
|
||||
var oldData, newData []byte
|
||||
var err error
|
||||
|
||||
err = p.ensureServerVersion("5.12.0")
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
var oldData, newData []byte
|
||||
|
||||
if oldValue != nil {
|
||||
oldData, err = json.Marshal(oldValue)
|
||||
if err != nil {
|
||||
@@ -53,9 +63,15 @@ func (p *HelpersImpl) KVCompareAndSetJSON(key string, oldValue interface{}, newV
|
||||
|
||||
// KVCompareAndDeleteJSON implements Helpers.KVCompareAndDeleteJSON.
|
||||
func (p *HelpersImpl) KVCompareAndDeleteJSON(key string, oldValue interface{}) (bool, error) {
|
||||
var oldData []byte
|
||||
var err error
|
||||
|
||||
err = p.ensureServerVersion("5.16.0")
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
var oldData []byte
|
||||
|
||||
if oldValue != nil {
|
||||
oldData, err = json.Marshal(oldValue)
|
||||
if err != nil {
|
||||
@@ -73,6 +89,11 @@ func (p *HelpersImpl) KVCompareAndDeleteJSON(key string, oldValue interface{}) (
|
||||
|
||||
// KVGetJSON implements Helpers.KVGetJSON.
|
||||
func (p *HelpersImpl) KVGetJSON(key string, value interface{}) (bool, error) {
|
||||
err := p.ensureServerVersion("5.2.0")
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
data, appErr := p.API.KVGet(key)
|
||||
if appErr != nil {
|
||||
return false, appErr
|
||||
@@ -81,7 +102,7 @@ func (p *HelpersImpl) KVGetJSON(key string, value interface{}) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, value)
|
||||
err = json.Unmarshal(data, value)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -89,8 +110,13 @@ func (p *HelpersImpl) KVGetJSON(key string, value interface{}) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// KVSetWithExpiryJSON implements Helpers.KVSetWithExpiryJSON.
|
||||
// KVSetWithExpiryJSON is a wrapper around KVSetWithExpiry to simplify atomically writing a JSON object with expiry to the key value store.
|
||||
func (p *HelpersImpl) KVSetWithExpiryJSON(key string, value interface{}, expireInSeconds int64) error {
|
||||
err := p.ensureServerVersion("5.6.0")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Ссылка в новой задаче
Block a user