Skip to content

Commit

Permalink
Merge ebe6f85 into 096d096
Browse files Browse the repository at this point in the history
  • Loading branch information
lirazgoldenthal committed Aug 14, 2019
2 parents 096d096 + ebe6f85 commit 80cdac0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject aerospike-clj "0.3.2"
(defproject aerospike-clj "0.3.3"
:description "An Aerospike Clojure client."
:url "https://github.com/AppsFlyer/aerospike-clj"
:license {:name "Eclipse Public License"
Expand Down
11 changes: 11 additions & 0 deletions src/aerospike_clj/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,17 @@
(put db index set-name payload expiration conf))
(map vector indices set-names payloads expirations)))))

(defn set
"`put` with a update policy"
([db index set-name data expiration]
(set db index set-name data expiration {}))
([db index set-name data expiration conf]
(_put db
index
((:transcoder conf identity) data)
(policy/set-policy (get-client db) expiration)
set-name)))

(defn create
"`put` with a create-only policy"
([db index set-name data expiration]
Expand Down
9 changes: 9 additions & 0 deletions src/aerospike_clj/policy.clj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
(set! (.recordExistsAction wp) record-exists-action)
wp)))

(defn ^WritePolicy set-policy
"Create a write policy with UPDATE record exists action.
in case of new entry, create it
in case the entry exists, update entry"
[client expiration]
(let [wp (write-policy client expiration)]
(set! (.recordExistsAction wp) RecordExistsAction/UPDATE)
wp))

(defn ^WritePolicy update-policy
"Create a write policy with `expiration`, expected `generation`
and EXPECT_GEN_EQUAL generation policy."
Expand Down
10 changes: 10 additions & 0 deletions test/aerospike_clj/client_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,13 @@
(is (= RecordExistsAction/REPLACE_ONLY (.recordExistsAction wp)))
(is (true? (.respondAllOps wp)))))


(deftest set-entry
(let [data (rand-int 1000)
update-data (rand-int 1000)]
(is (true? @(client/set *c* K _set data 100)))
(is (= data @(client/get-single-no-meta *c* K _set)))
(is (true? @(client/set *c* K _set update-data 100)))
(is (= update-data @(client/get-single-no-meta *c* K _set)))))


0 comments on commit 80cdac0

Please sign in to comment.